1
<!DOCTYPE html>
<html>
    <head>
        <title>Rango</title>
    </head>
        <h1>We Would Like to know your name </h1>
        <h2>192.168.29.109</h2>
     <label for="username">Username:</label>
    <input type="text" id="username" name="username" maxlength="10"><br><br>
        <button onclick="https://">GO FURTHER</button>
    <a href="/user/<username>">Submit</a><br /> 
        <a href="/rango/about">About</a><br />
        <img src="{{ user_image }}" alt="User Image">
    </div>
    </body>

</html>

from here python flask file I have only 1 file

#IMPORTING
from flask import Flask , render_template
from flask_script import Manager
from wtforms import StringField
import os


#Launching Server
app = Flask(__name__)
manager = Manager(app)


#Settings..!
PEOPLE_FOLDER = os.path.join('static', 'people_photo')
app.config['UPLOAD_FOLDER'] = PEOPLE_FOLDER




#Defining URL's And Rendering!
@app.route('/index')
def index():
   full_filename = os.path.join(app.config['UPLOAD_FOLDER'], 'lkj.jpg')
   return render_template("index.html", user_image = full_filename)


@app.route('/user/<name>')
def user(name):
 return '<h1>Hey %s, Welcome to Flask</h1>' % name




#Deployment
if __name__ == '__main__':
    manager.run()
    #app.run(debug=True)

Okay so I wanted to pass the value from input field to python flask file where I have defined @app.route(/user/) in the input field I asked someone's name he put the name and I wanted to take that name and put it in the user/ and display his name I can manually do that by writing the url myself like '192.168.29.10:5000/user/laxman' it would display 'Hey Laxman...etc' but I wanted that its done through the input field from that the parameters are passed and flask take that and display 'Hey Name...etc' so Can anyone help I only have two files and I have showed them already abobe SO anyone's help will be appreciated pls Thankyou :) If you want to ask anything ask I am gonna tell you! thankyou!

2
  • use form to submit value Commented Jul 7, 2020 at 11:55
  • CAN YOU ELAOBRATE MORE! Commented Jul 8, 2020 at 5:02

1 Answer 1

1

You can wrap your input into a form and submit it to the /user view.

<form action="/user"> 
  <input type="text" id="username" name="username" maxlength="10"><br><br>
  <button type="submit" name="button">Submit</button>
</form>

then in your view function

@app.route('/user')
def user():
   who = request.args.get('username')
   # Do something with who
   return render_template("user.html", name=who)
Sign up to request clarification or add additional context in comments.

2 Comments

How can I redirect it to another url with the username sir can I know? :)
I am not sure what exactly you mean. This will redirect to www.example.com/user?username=<who>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.