我有一个由Flask生成的网页,它应该根据用户的状态显示内容。你知道吗
目前,jinja2模板的相关部分如下所示:
{% if service.spotting_data.loco_id %}
Spotter Info *:<br />
{% if current_user.is_authenticated() %}
Loco: {{ service.spotting_data.loco_id }} <br />
Consist: {{ service.spotting_data.consist_info }}
{% else %}
We have information on the locomotive and consist for this service, however you need to <a href="{{ url_for('security.login') }}"> log in </a> to see it
{% endif %}
{% endif %}
当有人点击“登录”链接时,问题就出现了——此时他们只是被重定向回索引页,而不是包含此模板的页面。你知道吗
有没有办法在<a href>
上为{{url_for()}}
提供一个额外的标志,以确保用户登录后被重定向回这个页面?你知道吗
您需要将参数“next”传递给url\u。你知道吗
在呈现模板时,将请求对象发送到模板:
渲染模板(“模板.html,request=请求)
然后在模板中可以
{{url\'的安全.登录'下一个=请求路径)}}你知道吗
登录时您将被重定向回当前页面。。。你知道吗
相关问题 更多 >
编程相关推荐