官术网_书友最值得收藏!

The url_for function

The last interesting feature of Flask's routing system is the url_for() function. Given any view, it will return its actual URL.

Here's an example with the previous app:

    >>> from flask_converter import app 
>>> from flask import url_for
>>> with app.test_request_context():
... print(url_for('person', name='Tarek'))
...
/api/person/1

The previous example uses the Read-Eval-Print Loop (REPL), which you can get by running the Python executable directly.

This feature is quite useful in templates when you want to display the URLs of some views depending on the execution context. Instead of hardcoding some links, you can just point the function name to url_for to get it.

主站蜘蛛池模板: 来凤县| 郑州市| 沙坪坝区| 陵川县| 天祝| 青铜峡市| 搜索| 宾川县| 科尔| 玉溪市| 鄄城县| 左权县| 那曲县| 什邡市| 商水县| 尉犁县| 桃源县| 丽水市| 安丘市| 交城县| 仁寿县| 安西县| 临沭县| 东港市| 高要市| 景谷| 高安市| 炉霍县| 布尔津县| 祁门县| 凤翔县| 朔州市| 岳西县| 肥乡县| 崇仁县| 泌阳县| 浙江省| 南岸区| 昭平县| 岑巩县| 碌曲县|