0% found this document useful (0 votes)
6 views6 pages

Flask Routing Techniques Explained

The document discusses routing in Flask, a modern web framework, highlighting the use of the route() decorator to bind URLs to functions. It provides examples of defining routes and handling requests, including how to add multiple routes and the consequences of incorrect URL definitions. The document serves as a guide for implementing basic routing techniques in Flask applications.

Uploaded by

Shekhar Jalane
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

Flask Routing Techniques Explained

The document discusses routing in Flask, a modern web framework, highlighting the use of the route() decorator to bind URLs to functions. It provides examples of defining routes and handling requests, including how to add multiple routes and the consequences of incorrect URL definitions. The document serves as a guide for implementing basic routing techniques in Flask applications.

Uploaded by

Shekhar Jalane
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

3

Routing in Flask
Application
Mr. Shekhar D Jalane

Web Technology-I
Routing Technique
2

 Modern web frameworks use the routing


technique to help a user remember
application URLs.
 The route() decorator in Flask is used to
bind URL to a function.

@[Link]('/hello’) # @[Link]('/')
def hello_world():
return 'Hello World’
Web Technology-I
Flask Application
3

from flask import Flask


app = Flask(__name__)
@[Link]('/’)
def hello_world():
return 'Hello World’
if __name__ == '__main__’:
[Link]()
Web Technology-I
Bind Rule
4

 URL ‘/hello’ rule is bound


the hello_world() function.
 As a result, if a user
visits [Link]
he output of the hello_world() function
will be rendered in the browser

Web Technology-I
add_url_rule()
5

def hello_world():
return ‘hello world’
app.add_url_rule(‘/’, ‘hello’, hello_world)

Web Technology-I
Add multiple Routes
6

from flask import Flask


app = Flask(__name__)

@[Link]('/flask') #Add /flask/ URL results in 404 Not


Found page
def hello_flask():
return 'Hello Flask'

@[Link]('/python/')
def hello_python():
return 'Hello Python'

if __name__ == '__main__':
[Link]()
Web Technology-I

You might also like