假设我有以下结构:
/root/user/login
我在蓝图中登录:
app.register_blueprint(login_blueprint,url_prefix=prefix('/user'))
我可以重定向到“.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)
重定向使我转到/root/user
:
redirect(url_for('.index'))
但是如何到达/root
(相对于当前url(..
)呢?
可以向
url_for
传递/root/
的终结点函数的名称。例如,如果您有:
在应用程序的其他地方,您可以执行以下操作:
在这里引起重定向。当您将
.
放在传递给url_for
的字符串前面时,这将告诉它在当前蓝图中查找端点。关闭.
,告诉它在app
中查找端点相关问题 更多 >
编程相关推荐