Difference between revisions of "Parts of a Flask Web App"
(Created page with "=@app.route= This defines where a particular path in the url relates too: <syntaxhighlight lang=python> @app.route("/") def hello(): return "Hello World!" </syntaxhighlig...") |
(→Parameters) |
||
Line 34: | Line 34: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | Using this method the parameters are passed as strings, and you may need to convert them. | + | Using this method the parameters are passed as strings, and you may need to convert them. In this example the URL '/Wayne' will display the message 'Hello Wayne'. |
+ | |||
+ | =Defining url_for= | ||
+ | |||
+ | =Handling HTML Forms= | ||
+ | |||
+ | =Using Sessions= | ||
+ | |||
+ | =Templates= |
Revision as of 07:48, 10 April 2019
Contents
@app.route
This defines where a particular path in the url relates too:
@app.route("/")
def hello():
return "Hello World!"
When the app server is running, visiting the root will produce the message 'Hello World!'. The code below will also display this if you visit '/home' on the app server:
@app.route("/")
@app.route("/home")
def hello():
return "Hello World!"
Parameters
The example below will just display the message:
@app.route("/")
def hello():
return "Hello World!"
You can also use parameters:
@app.route("/<name>")
def hello(name):
return "Hello "+name
Using this method the parameters are passed as strings, and you may need to convert them. In this example the URL '/Wayne' will display the message 'Hello Wayne'.