- Python Web - Django Framework
- Django Framework - Overview
- Django Framework - Users
- Django Framework - Installation
- Django Framework - Creating Application
- Python Web - Flask Framework
- Python Web - Flask Framework
- Flask Framework - Creating URL Routing
- Flask Framework - Using Templates
- Python Web - Pyramid Framework
- Python Web - Pyramid Framework
- Pyramid Framework - Core Concepts
- Pyramid Framework - Creating Application
- Python Web - Dash Framework
- Python Web - Dash Framework
- Dash Framework - App Layout
- Dash Framework - HTML Component
- Dash Framework - Visualization
- Python Web - py4web Framework
- Python Web - py4Web Framework
- py4web Framework - Dashboard
- py4web Framework - Creating Application
- Python Web - Miscellaneous
- Python Web - Web2py Framework
- Python Web - Choosing a Better Framework
- Python Web Development Libraries Resources
- Python Web - Quick Guide
- Python Web - Useful Resources
- Python Web - Discussion
Selected Reading
Flask Framework - Creating URL Routing
URL Routing makes URLs in your Web app easy to remember. We will now create some URL routes −
/hello /members /members/name
Example - Creating Routes based on URLs
We can write the following code based on the above URL and save it as main.py.
main.py
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return "Index!"
@app.route('/hello')
def hello():
return "Hello, World!"
@app.route("/members")
def members():
return "Members"
@app.route("/members//")
def getMember(name):
return name
if __name__ == '__main__':
app.run(debug=True)
Output
Run the above code to verify the output −
py main.py
Running on http://localhost:5000/
We will get the following output in our browser −
We can try other URLs in our browser as follows −
Running on http://localhost:5000/hello, will give the following output −
Running on http://localhost:5000/members, will give −
Running on http://localhost:5000/members/TutorialsPoint/, will give you the following output −
Advertisements