g.current_user请教下是不是必须得这么写?

来源:9-8 登录功能实现(2)

慕慕7551115

2021-07-04

老师,请教下,g.current_user请教下是不是必须得这么写?比如写成g.current_user1是否就不行?
开始我以为这是随便定义的,后来发现如果写成其他值如:g.current_user1,导致后续登录成功后,用户名获取不到

写回答

1回答

慕慕7551115

提问者

2021-07-04

 File "D:\process\python\process\maoyan\templates\index.html", line 1, in top-level template code

    {% extends "common/layout.html" %}

  File "D:\process\python\process\maoyan\templates\common\layout.html", line 36, in top-level template code

    <li><a href="javascript:void(0);">{{current_user1.nickname}}</a></li> 

  File "C:\Users\Administrator\AppData\Roaming\Python\Python36\site-packages\jinja2\environment.py", line 474, in getattr

    return getattr(obj, attribute)

jinja2.exceptions.UndefinedError: 'current_user' is undefined

INFO:werkzeug:127.0.0.1 - - [04/Jul/2021 19:00:10] "GET / HTTP/1.1" 500 -


0
1
编程浪子
你好 可以随便改名字,但是相关地方要改完,不然就会报错。g是flask 全局变量的一个简称 ---------- 最后非常抱歉,最近身体出了点问题,非常抱歉。
2021-08-28
共1条回复

Python Flask入门与进阶 开发电影网站

从只会Python基础语法到

820 学习 · 283 问题

查看课程