Django错误:TypeError at / 'bool' object is not callable解决

作者:希希里之海 时间:2022-12-26 22:38:05 

使用 Django自带的 auth 用户验证功能,编写函数,使用 is_authenticated 检查用户是否登录,结果报错:

TypeError at / 'bool' object is not callable

编写函数如下:


def index(request, pid=None, del_pass=None):
 if request.user.is_authenticated():
   username = request.user.username
   useremail = request.user.email
 messages.get_messages(request)
 template = get_template('index.html')
 html = template.render(context=locals(), request=request)
 return HttpResponse(html)

查询相关资料,发现 is_authenticated 是属性而不是方法,我们应该把括号去掉,这样就没什么问题了。

if request.user.is_authenticated():

改为

 if request.user.is_authenticated:

来源:https://www.cnblogs.com/weixuqin/p/9298746.html

标签:django,错误,typeerror
0
投稿

猜你喜欢

  • Python读写Json涉及到中文的处理方法

    2021-10-29 10:26:24
  • Python实现PS滤镜中的USM锐化效果

    2023-07-10 12:58:24
  • 深入理解Python虚拟机中的Code obejct

    2023-05-05 02:39:31
  • MySQL 连接与管理

    2011-09-10 15:52:42
  • python基础教程项目五之虚拟茶话会

    2022-10-25 02:08:47
  • Python决策树之基于信息增益的特征选择示例

    2023-01-09 23:44:32
  • 浅谈python函数之作用域(python3.5)

    2021-09-22 05:49:42
  • OpenCV 图像梯度的实现方法

    2023-07-14 08:25:43
  • python中PIL安装简单教程

    2021-05-07 01:33:12
  • Selenium定时刷新网页的实现代码

    2021-09-30 04:01:00
  • Python scikit-learn 做线性回归的示例代码

    2022-05-03 11:00:54
  • asp小偷程序原理和简单示例

    2007-11-05 17:12:00
  • JavaScript 实现 Konami Code

    2009-05-26 12:44:00
  • 学会Python数据可视化必须尝试这7个库

    2022-03-26 20:37:25
  • python模块简介之有序字典(OrderedDict)

    2023-12-14 07:46:46
  • 关于Python中的编码规范

    2021-11-07 02:38:02
  • 详解Python OpenCV图像分割算法的实现

    2022-11-28 13:15:44
  • Python爬虫之批量下载喜马拉雅音频

    2022-09-25 20:18:27
  • Python替换NumPy数组中大于某个值的所有元素实例

    2021-11-11 07:36:20
  • python按比例随机切分数据的实现

    2021-05-28 05:17:34
  • asp之家 网络编程 m.aspxhome.com