![]() URL building handles escaping of special characters transparently. You can change your URLs in one go instead of needing to remember to Reversing is often more descriptive than hard-coding the URLs. Url_for() instead of hard-coding them into your templates? Why would you want to build URLs using the URL reversing function Unknown variable parts are appended to the URL as query parameters. Keyword arguments, each corresponding to a variable part of the URL rule. It accepts the name of the function as its first argument and any number of To build a URL to a specific function, use the url_for() function. Keep URLs unique for these resources, which helps search engines avoid Trailing slash ( /about/) produces a 404 “Not Found” error. The canonical URL for the about endpoint does not have a trailing If you access the URL withoutĪ trailing slash ( /projects), Flask redirects you to the canonical URL It’s similar to a folder in a file system. The canonical URL for the projects endpoint has a trailing slash. route ( '/about' ) def about (): return 'The about page' route ( '/projects/' ) def projects (): return 'The project page'. You need to tell the Flask where your application To run the application, use the flask command or Your application flask.py because this would conflict with Flask Save it as hello.py or something similar. The default content type is HTML, so HTML in the string The function returns the message we want to display in the user’sīrowser. We then use the route() decorator to tell Flask This is needed so that Flask knows where to look for resources such _name_ is aĬonvenient shortcut for this that is appropriate for most cases. Name of the application’s module or package. Next we create an instance of this class. route ( "/" ) def hello_world (): return "Hello, World!"įirst we imported the Flask class. From flask import Flask app = Flask ( _name_ ). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |