Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用Flask安全性保护页面的一部分_Python_Redirect_Flask_Jinja2_Flask Security - Fatal编程技术网

Python 使用Flask安全性保护页面的一部分

Python 使用Flask安全性保护页面的一部分,python,redirect,flask,jinja2,flask-security,Python,Redirect,Flask,Jinja2,Flask Security,我有一个由Flask生成的网页,根据用户的状态显示内容 目前,jinja2模板的相关部分如下所示: {% if service.spotting_data.loco_id %} Spotter Info *:<br /> {% if current_user.is_authenticated() %} Loco: {{ service.spotting_data.loco_id }} <br /> Consist: {{ s

我有一个由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 %}
{%if service.spotting_data.loco_id%}
观察员信息*:
{%如果当前用户是经过身份验证的用户。{u()%} 本地:{{service.spotting_data.Loco_id}}
组成:{{service.spotting_data.compost_info} {%else%} 我们有这项服务的机车和编组信息,但是您需要查看 {%endif%} {%endif%}
当有人点击“登录”链接时,问题就出现了——此时他们只是被重定向回索引页面,而不是包含此模板的页面


有没有办法在
{{url\u for()}}
上为
添加一个附加标志,以确保用户登录后重定向回此页面

您需要将参数“next”传递给url\u,以便

渲染模板时,将请求对象发送到模板:

render_模板(“template.html”,request=request)

然后在模板中,您可以执行以下操作

{{url_for('security.login',next=request.path)}


登录时,您将被重定向回当前页面…

如果您自己解决了这个问题,您可以将其添加为答案,然后接受它。不需要在问题本身中添加答案。你不能结束一个问题,但你当然可以添加一个答案。好的,谢谢。我试过了,但上面说我在发帖后8小时才被允许回答我的问题。正确。稍后再回来,把答案贴出来。