About Lesson
In this Flask Tutorial we are going to learn about Passing Parameters to URL, we have already learned that how you can create url and routes in Flask.
This is our app.py file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
from flask import Flask #create the object of Flask app = Flask(__name__) #creating our routes @app.route('/') def Index(): return "<h1>Geekscoders.com, Hello Flask Application</h1>" @app.route('/contact') def Contact(): return "<h1>Geekscoders.com, Contact Page</h1>" @app.route('/about') def About(): return "<h1>Geekscoders.com, About Page</h1>" #passing parametrs to the routes @app.route('/user/<name>') def User(name): return "<h1>Welcome to : {}</h1>".format(name) #run flask app if __name__ == "__main__": app.run(debug=True) |
This is our new route that we want to pass parameters, and basically we are passing a name with our route.
1 2 3 |
@app.route('/user/<name>') def User(name): return "<h1>Welcome to : {}</h1>".format(name) |
Now run your Flask application and go to http://localhost:5000/user/geekscoders, this will be the result.