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

简介: 使用 Django自带的 auth 用户验证功能,编写函数,使用 is_authenticated 检查用户是否登录,结果报错:  TypeError at / 'bool' object is not callable  编写函数如下:def index(request, pid=None, del_pass=None): if request.

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

 

相关文章
|
11月前
|
Python
Python错误 TypeError: ‘NoneType‘ object is not subscriptable解决方案汇总
Python错误 TypeError: ‘NoneType‘ object is not subscriptable解决方案汇总
|
6月前
|
Python Windows
xlrd库报错【AttributeError: ‘ElementTree‘ object has no attribute ‘getiterator‘】
xlrd库报错【AttributeError: ‘ElementTree‘ object has no attribute ‘getiterator‘】
116 0
|
Python
运行项目时flask_sqlalchemy报错AttributeError: ‘LocalStack‘ object has no attribute ‘__ident_func__‘
1.原因 是由于flask_sqlalchemy版本不匹配导致的,我们需要自动获取正确的包版本
622 1
|
11月前
|
Python
Python 报错AttributeError: ‘str‘ object has no attribute ‘decode‘解决办法
Python 报错AttributeError: ‘str‘ object has no attribute ‘decode‘解决办法
|
PyTorch 算法框架/工具
torch中报错:AttributeError: 'builtin_function_or_method' object has no attribute 'detach'怎么解决?
这个错误信息 "AttributeError: 'builtin_function_or_method' object has no attribute 'detach'" 表示你尝试在一个内置函数或方法对象上调用 detach() 方法,而这种对象没有这个属性。 detach() 是 PyTorch 张量和变量的方法,允许它们从计算图中分离出来,因此不能在其他类型的对象上调用。要解决这个错误,请确保你正在一个 PyTorch 张量或变量上调用 detach() 方法。
833 0
|
Python
Python错误:'tuple' object is not callable
Python错误:'tuple' object is not callable
175 0
Python报错:TypeError: a bytes-like object is required, not ‘str‘
Python报错:TypeError: a bytes-like object is required, not ‘str‘
Python报错:TypeError: a bytes-like object is required, not ‘str‘
|
数据采集 Python
error: scrapy TypeError: 'float' object is not iterable
error: scrapy TypeError: 'float' object is not iterable
234 0
|
Python
Flask - 访问返回字典的接口报错:The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a dict.
Flask - 访问返回字典的接口报错:The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a dict.
1400 0
Flask - 访问返回字典的接口报错:The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a dict.
|
Web App开发 API C#
Pywinauto 应用后端类型选择错误:AttributeError: ‘NoneType‘ object has no attribute ‘backend‘. 原因及解决办法
Pywinauto 应用后端类型选择错误:AttributeError: ‘NoneType‘ object has no attribute ‘backend‘. 原因及解决办法
309 0
Pywinauto 应用后端类型选择错误:AttributeError: ‘NoneType‘ object has no attribute ‘backend‘. 原因及解决办法