当前位置:网站首页>Flask framework learning: trailing slashes for routes
Flask framework learning: trailing slashes for routes
2022-08-11 05:33:00 【weixin_42576837】
URL redirect behavior
The trailing slash of the route is different, for example:
from flask import Flaskapp = Flask(__name__)@app.route('/')def index():return 'index page'@app.route('/qwe')def test():return 'test'if __name__ == '__main__':app.run()When accessing the route /qwe, the route should be written as /qwe, which can be accessed, but if it is written as /qwe/will report an error
/qweVisit
/qwe/Visit
The error code is 404: the resource corresponding to this url cannot be found
If the code is modified to:
@app.route('/qwe/')# followed by a slashdef test():return 'test'Both access methods are available, you can try it yourself.
Notice that when you enter /qwe in the browser address bar, it will automatically become /qwe/, this is because flask automatically redirects, check the returnStatus code: 

means that the accessed /qwe is permanently transferred to /qwe/, so the redirection is performed automatically.
So if the route does not have / at the end, you cannot add a slash when accessing it.
In addition, if you modify the code now to @app.route('/qwe'), remove the slashes and run it again, there will always be an error, because it keeps redirecting, then clear the browserJust cache it.
边栏推荐
猜你喜欢

Internet Protocol 1

【嵌入式开源库】MultiButton的使用,简单易用的事件驱动型按键驱动模块

redis分布式锁

Unity WebGL RuntimeError: integer overflow

Redis - Data Types (Basic Instructions, String, List, Set, Hash, ZSet, BitMaps, HyperLogLog, GeoSpatial) / Publish and Subscribe

【嵌入式开源库】cJSON的使用,高效精简的json解析库

Switch and Router Technology-34-Dynamic NAT

Sub-database sub-table ShardingSphere-JDBC notes arrangement

Delphi7学习记录-demo实例

分库分表之sharding-proxy
随机推荐
Decryption of BitLocker
什么是三次握手和四次挥手(清晰易懂)
Oracle中如何用一个表的数据更新另一个表中的数据_转载
JedisLock_Redis分布式锁实现_转载
切分字符串进行输出显示
Trilium使用总结
输入字符串,替换其中敏感词进行输出
华为od德科面试数据算法解析 2022-8-10 迷宫问题
Weekly recommended short video: your commonly used Polaroid, its predecessor turned out to be like this!
Switch and Router Technology-34-Dynamic NAT
MySQL存储引擎概念
3 Module 2: Use of scientific research tools
分库分表ShardingSphere-JDBC笔记整理
宝塔Linux环境下redis开启多端口
Flask框架学习:模板继承
Redis-数据类型(基本指令、String、List、Set、Hash、ZSet、BitMaps、HyperLogLog、GeoSpatial)/发布和订阅
让你代码越来越高大上的技巧——代码规范,你得知道
第二篇 DS5 Armv8 样例工程报错之GCC编译
代码在线审查(添加网页批注)的实现
【嵌入式开源库】使用J-Link打印日志,让你节省一个打印串口