5 python url url-rewriting flask
Is it possible to rewrite a URL with Flask e.g. if a POST request is received via this route:
@app.route('/', methods=['GET','POST'])
def main():
if request.method == 'POST':
#TODO: rewrite url to something like '/message'
return render_template('message.html')
else:
return render_template('index.html')
Run Code Online (Sandbox Code Playgroud)
I'm aware I can use a redirect and setup another route but I prefer to simply modify the url if possible.
hea*_*ad7 -1
我认为您可能对重定向行为感兴趣
from flask import Flask,redirect
Run Code Online (Sandbox Code Playgroud)
然后使用
redirect("http://www.example.com", code=302)
Run Code Online (Sandbox Code Playgroud)