Tutorial by Examples

The following example is an example of a basic server: # Imports the Flask class from flask import Flask # Creates an app and checks if its the main or imported app = Flask(__name__) # Specifies what URL triggers hello_world() @app.route('/') # The function run on the index route def hello...
With Flask, URL routing is traditionally done using decorators. These decorators can be used for static routing, as well as routing URLs with parameters. For the following example, imagine this Flask script is running the website www.example.com. @app.route("/") def index(): return ...
The two most common HTTP methods are GET and POST. Flask can run different code from the same URL dependent on the HTTP method used. For example, in a web service with accounts, it is most convenient to route the sign in page and the sign in process through the same URL. A GET request, the same that...
Instead of typing our HTML markup into the return statements, we can use the render_template() function: from flask import Flask from flask import render_template app = Flask(__name__) @app.route("/about") def about(): return render_template("about-us.html") if __n...
Similar to Meteor.js, Flask integrates well with front end templating services. Flask uses by default Jinja Templating. Templates allow small snippets of code to be used in the HTML file such as conditionals or loops. When we render a template, any parameters beyond the template file name are pass...
The request object provides information on the request that was made to the route. To utilize this object, it must be imported from the flask module: from flask import request URL Parameters In previous examples request.method and request.form were used, however we can also use the request.args...

Page 1 of 1