Rewrite a URL with Flask

12,560

I think you could be interested in redirect behavior

from flask import Flask,redirect

then use

redirect("http://www.example.com", code=302)

see: Redirecting to URL in Flask

Share:
12,560
Admin
Author by

Admin

Updated on August 03, 2022

Comments

  • Admin
    Admin over 1 year

    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')
    

    I'm aware I can use a redirect and setup another route but I prefer to simply modify the url if possible.