使用flask_login会话与jinja2模板 [英] Using flask_login session with jinja2 templates

查看:140
本文介绍了使用flask_login会话与jinja2模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的注册/登录链接jinja2模板,我应该隐藏他们,当用户登录,我也使用flask_login模块这个东西。



问题是:我应该如何识别用户是否在jinja2模板中登录?

current_user 变量添加到您的模板中:

<$>
p $ p> {%if current_user.is_authenticated%}
...
{%else%}
...
{%endif%}

他们在文档


I have simple jinja2 template with registration/login links, I should hide them when user logged in, I also use flask_login module for this stuff.

Question is: How should I identify is user logged in in jinja2 templates?

解决方案

Flask-Login adds the current_user variable to your templates:

{% if current_user.is_authenticated %}
    ...
{% else %}
    ...
{% endif %}

They mention this briefly in the documentation.

这篇关于使用flask_login会话与jinja2模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆