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

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.

主站蜘蛛池模板: 永德县| 岗巴县| 安徽省| 宣武区| 逊克县| 巴东县| 都匀市| 潮州市| 修文县| 河南省| 河南省| 衢州市| 莱阳市| 化州市| 唐海县| 沙雅县| 双桥区| 红安县| 和顺县| 北碚区| 含山县| 盐山县| 波密县| 木兰县| 平凉市| 宁远县| 通化县| 乌审旗| 攀枝花市| 永新县| 绥化市| 礼泉县| 北辰区| 罗源县| 桂林市| 石柱| 茌平县| 广安市| 塔城市| 安徽省| 枣庄市|