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

yipeiwu_com6年前Python基础

使用 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:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python字符串编码识别模块chardet简单应用

python的字符串编码识别模块(第三方库): 官方地址: http://pypi.python.org/pypi/chardet import chardet import...

Django 1.10以上版本 url 配置注意事项详解

在改造旧版本django cms程序从 pyton2.7, django 1.8版本升到 python 3.5,django 1.11版本的时候,原以为会非常轻松,却不想在URL配置上就...

python3解析库pyquery的深入讲解

前言 pyquery是一个类似jquery的python库,它实现能够在xml文档中进行jQuery查询,pyquery使用lxml解析器进行快速在xml和html文档上操作,它提供了和...

python调用webservice接口的实现

python调用webservice接口的实现

使用suds这个第三方模块 from suds.client import Client url = 'http://ip:port/?wsdl' cilent=Client...

Python 使用 Pillow 模块给图片添加文字水印的方法

Python 使用 Pillow 模块给图片添加文字水印的方法

像微博一类的平台上传图片时,平台都会添加一个水印,宣誓着对图片的所有权,我们自己的博客平台也可以给自己的图片添加上水印。 还是用 Pillow 模块来实现 先来看一个简单的例子 &g...