How do I redirect flasks to the parent drawing?

Suppose I have the following structure:

/root/user/login 

I am making a login in the project:

  app.register_blueprint(login_blueprint,url_prefix=prefix('/user')) 

I can redirect to .index:

 @login_blueprint.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': #### this redirects me to '/root/user/' redirect_to_index= redirect(url_for('.index')) response = current_app.make_response(redirect_to_index) # do the log in return response redirect_to_index=redirect(url_for('.index')) response = current_app.make_response(redirect_to_index) 

Redirecting leads me to /root/user :

 redirect(url_for('.index')) 

But how to get to /root (what is connected with the current url ( .. )?

+4
source share
1 answer

You can pass url_for the endpoint function name for /root/ .

For example, if you have:

 @app.route('/root/') def rootindex(): return "this is the index for the whole site." 

elsewhere in your application you can:

 redirect(url_for('rootindex')) 

To trigger a redirect here. When you put . before the line, you go to url_for , which tells it to look for the endpoint in the current project. If you leave . off, you tell him to search for the endpoint in the app

+6
source

Source: https://habr.com/ru/post/1495247/


All Articles