加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

flask开发中遇到jinja2.exceptions.UndefinedError:'current

发布时间:2020-12-17 17:03:29 所属栏目:Python 来源:网络整理
导读:flask开发中遇到jinja2.exceptions.UndefinedError jinja2.exceptions.UndefinedError: 'current' is undefined 检查打开网址对应的页面是否有代码编写错误。 代码示例: {%?extends?"base.html"?%}{%?import?"bootstrap/wtf.html"?as?wtf?%}{%?block?title?%

flask开发中遇到jinja2.exceptions.UndefinedError jinja2.exceptions.UndefinedError: 'current' is undefined

检查打开网址对应的页面是否有代码编写错误。

代码示例:

{%?extends?"base.html"?%}
{%?import?"bootstrap/wtf.html"?as?wtf?%}
{%?block?title?%}Flasky{%?endblock?%}
{%?block?page_content?%}
<div?class="page-header">
????<h1>Hello,?{%?if?current.user.is_authenticated?%}
????????{{?current_user.username?}}
????????{%?else?%}
????????Stranger
????????{%?endif?%}
????!</h1>
????<!--如果该用户信息存在数据库-->
????{%?if??known?%}
????<p>非常高兴再次看见你</p>
????{%?else?%}
????<p>很高兴认识你</p>
????{%?endif?%}
</div>
{{?wtf.quick_form(form)?}}
{%?endblock?%}

发现以下代码写错

????<h1>Hello,?{%?if?current.user.is_authenticated?%}
????????{{?current_user.username?}}
????????{%?else?%}
????????Stranger
????????{%?endif?%}
????</h1>

正确写法是?

current_user


(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读