return render_template("index/index.html")报错
来源:5-1 管理员登录和列表页面
慕容8405126
2021-03-02
return render_template(“index/index.html”)报错
jinja2.exceptions.UndefinedError
jinja2.exceptions.UndefinedError: ‘current_user’ is undefined
Traceback (most recent call last)
File “C:\Users\a1235\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py”, line 2464, in call
return self.wsgi_app(environ, start_response)
File “C:\Users\a1235\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py”, line 2450, in wsgi_app
response = self.handle_exception(e)
File “C:\Users\a1235\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py”, line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File “C:\Users\a1235\AppData\Local\Programs\Python\Python36\lib\site-packages\flask_compat.py”, line 39, in reraise
raise value
File “C:\Users\a1235\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py”, line 2447, in wsgi_app
response = self.full_dispatch_request()
File “C:\Users\a1235\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py”, line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File “C:\Users\a1235\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py”, line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File “C:\Users\a1235\AppData\Local\Programs\Python\Python36\lib\site-packages\flask_compat.py”, line 39, in reraise
raise value
File “C:\Users\a1235\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py”, line 1950, in full_dispatch_request
rv = self.dispatch_request()
File “C:\Users\a1235\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py”, line 1936, in dispatch_request
return self.view_functionsrule.endpoint
File “D:\python_project\flask_MVC\web\controllers\index.py”, line 7, in index
return render_template(“index/index.html”)
File “C:\Users\a1235\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\templating.py”, line 140, in render_template
ctx.app,
File “C:\Users\a1235\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\templating.py”, line 120, in _render
rv = template.render(context)
File “C:\Users\a1235\AppData\Local\Programs\Python\Python36\lib\site-packages\jinja2\environment.py”, line 1090, in render
self.environment.handle_exception()
File “C:\Users\a1235\AppData\Local\Programs\Python\Python36\lib\site-packages\jinja2\environment.py”, line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File “C:\Users\a1235\AppData\Local\Programs\Python\Python36\lib\site-packages\jinja2_compat.py”, line 28, in reraise
raise value.with_traceback(tb)
File “D:\python_project\flask_MVC\web\templates\index\index.html”, line 1, in top-level template code
{% extends “common/layout_main.html” %}
File “D:\python_project\flask_MVC\web\templates\common\layout_main.html”, line 74, in top-level template code
姓名:{{ current_user.nickname }} 编辑
File “C:\Users\a1235\AppData\Local\Programs\Python\Python36\lib\site-packages\jinja2\environment.py”, line 471, in getattr
return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: ‘current_user’ is undefined
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the “Traceback” headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.
You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:
dump() shows all variables in the frame
dump(obj) dumps all that’s known about the object
1回答
-
你好
current_user 是公用布局layout 里面的,我觉得如果你是看到 5-1 章节,是不是用了完整源码中的页面了,这样应该就是复制错了
112021-03-10
相似问题