python - flask中在模板中使用current_user.is_authenticated,运行报错,提示没定义
PHP中文网
PHP中文网 2017-04-18 10:22:20
0
2
1033

flask中在模板中使用current_user.is_authenticated,运行报错,提示没定义

报错信息

Traceback (most recent call last):
  File "E:\Python\Python35-32\lib\site-packages\flask\app.py", line 2000, in __call__
    return self.wsgi_app(environ, start_response)
  File "E:\Python\Python35-32\lib\site-packages\flask\app.py", line 1991, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "E:\Python\Python35-32\lib\site-packages\flask\app.py", line 1567, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "E:\Python\Python35-32\lib\site-packages\flask\_compat.py", line 33, in reraise
    raise value
  File "E:\Python\Python35-32\lib\site-packages\flask\app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "E:\Python\Python35-32\lib\site-packages\flask\app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "E:\Python\Python35-32\lib\site-packages\flask\app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "E:\Python\Python35-32\lib\site-packages\flask\_compat.py", line 33, in reraise
    raise value
  File "E:\Python\Python35-32\lib\site-packages\flask\app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "E:\Python\Python35-32\lib\site-packages\flask\app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "D:\1file\pythontest\blog\blog.py", line 90, in login
    return render_template("/login.html", form=form)
  File "E:\Python\Python35-32\lib\site-packages\flask\templating.py", line 134, in render_template
    context, ctx.app)
  File "E:\Python\Python35-32\lib\site-packages\flask\templating.py", line 116, in _render
    rv = template.render(context)
  File "E:\Python\Python35-32\lib\site-packages\jinja2\environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
  File "E:\Python\Python35-32\lib\site-packages\jinja2\environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "E:\Python\Python35-32\lib\site-packages\jinja2\_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "D:\1file\pythontest\blog\templates\login.html", line 1, in top-level template code
    {% extends "base.html"%}
  File "D:\1file\pythontest\blog\templates\base.html", line 1, in top-level template code
    {% extends "bootstrap/base.html" %}
  File "E:\Python\Python35-32\lib\site-packages\flask_bootstrap\templates\bootstrap\base.html", line 1, in top-level template code
    {% block doc -%}
  File "E:\Python\Python35-32\lib\site-packages\flask_bootstrap\templates\bootstrap\base.html", line 4, in block "doc"
    {%- block html %}
  File "E:\Python\Python35-32\lib\site-packages\flask_bootstrap\templates\bootstrap\base.html", line 20, in block "html"
    {% block body -%}
  File "E:\Python\Python35-32\lib\site-packages\flask_bootstrap\templates\bootstrap\base.html", line 21, in block "body"
    {% block navbar %}
  File "D:\1file\pythontest\blog\templates\base.html", line 12, in block "navbar"
    {% if current_user.is_authenticated %}
  File "E:\Python\Python35-32\lib\site-packages\jinja2\environment.py", line 408, in getattr
    return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'current_user' is undefined
PHP中文网
PHP中文网

认证高级PHP讲师

모든 응답(2)
小葫芦

초기 구성에서 한 문장이 누락된 것을 발견했습니다

으아악

추가만 하세요

刘奇

current_user가 플라스크 로그인 플러그인에 의해 주입된 것 같습니다

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿