Finally, to issue a redirect to the ticker page, we use the redirect function from Flask and pass in the URL we want to send users to. The request that we can import from Flask can be used within routes to get information about the current request that Flask is serving. Once we have the routing set up, we can access the form data through Flask's request object. This route is going to receive a POST request from the HTML form, so we need to explicitly tell Flask to route POST requests to it by passing "POST" into the optional methods argument to the route decorator, like so methods=) from flask import request app.route ('/login', methods 'GET', 'POST') def login (): if thod 'POST': dothelogin () else: showtheloginform () You can also map different functions to the same endpoint based on the HTTP method used. A popular choice is Redis, which is easy to set-up and use. Flask-Cache can be configured to work with a bunch of different caching backends. This extension provides us with a decorator that we can use on our index view to cache the response for some period of time. By default, Flask assumes routes you define are responding to GET requests. You can change this behavior by supplying the methods argument to the route () decorator. Specifically, we’re going to use the Flask-Cache extension. So far we have only been dealing with GET requests (when our browser requests a page). To support a form, we're going to need to a route that accepts the input and redirects users to the right page. Update any references to the path in url_for with the prefix being the name of the blueprint ( home.index).Create a folder in the templates folder for the blueprint, move templates. ![]() route ( '/' ) def index ( ) : return render_template ( 'home/index.html' ) From flask import Blueprint, render_template
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |