Gab*_*lis 13 python google-app-engine url-routing flask
我正在使用Flask 0.9.我有使用Google App Engine的经验.
在GAE中,url匹配模式按照它们出现的顺序进行评估,先到先得.Flask中的情况是一样的吗?
在Flask中,如何编写url匹配模式来处理所有其他不匹配的URL.在GAE中,你只需要把它放在/.*最后,比如:('/.*', Not_Found).如果Flask不支持正则表达式,如何在Flask中做同样的事情.
cle*_*leg 16
如果您需要处理服务器上找不到的所有网址 - 只需创建404 hanlder:
@app.errorhandler(404)
def page_not_found(e):
# your processing here
return result
Run Code Online (Sandbox Code Playgroud)jus*_*nas 15
这适用于您的第二个问题.
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'This is the front page'
@app.route('/hello/')
def hello():
return 'This catches /hello'
@app.route('/<path:dummy>')
def fallback(dummy):
return 'This one catches everything else'
Run Code Online (Sandbox Code Playgroud)
path会抓住一切直到最后.更多关于变量转换器.
| 归档时间: |
|
| 查看次数: |
12076 次 |
| 最近记录: |