我正在尝试使用Flask编写一个程序,让您快速创建页面。基本上,我想这样做,以便在动态网址中使用斜杠(/
),例如路线为<page>
,我输入了localhost:5000/test/page
,我希望它以<page>
为<page>
到test/page
。
这可能吗?
答案 0 :(得分:1)
摘自URL variables上的Flask文档:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!\n'
@app.route('/path/<path:subpath>')
def show_subpath(subpath):
return 'Subpath %s\n' % subpath
从命令行请求的示例:
$ curl http://127.0.0.1:5000
Hello, World!
$ curl http://127.0.0.1:5000/path/test/page
Subpath test/page
如果您想对正则表达式做类似的事情,则常见的解决方案似乎是adding a regex 'converter',但是path
URL变量似乎完全符合您的要求。