Flask URL Building
- url_for() function - It is used to build a URL to the specific function dynamically. The first parameter is the name of the particular function, and then you can pass any number of keyword parameter corresponding to the variable part of the URL.
For ex, the URL http://localhost:5000/user/admin is redirected to the URL http://localhost:5000/admin, the URL localhost:5000/user/librarion, is redirected to the URL http://localhost:5000/librarion, the URL http://localhost:5000/user/student is redirected to the URL http://localhost/student.
Benefits of the Dynamic URL Building
- Avoids hard coding of the URLs.
- Change the URLs dynamically instead of remembering the manually changed hard-coded URLs.
- It handles the escaping of special characters and Unicode data transparently.
- If your application is placed outside the URL root, url_for() properly handles that for you.
- The generated paths are always absolute, avoiding unexpected behavior of relative paths in browsers.
If you want to learn about Python Course , you can refer the following links Python Training in Chennai , Machine Learning Training in Chennai , Data Science Training in Chennai , Artificial Intelligence Training in Chennai