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

Django 错误:TypeError at / 'bool' object is not callable的更多相关文章

  1. 解决Flask和Django的错误“TypeError: 'bool' object is not callable”

    跟着欢迎进入Flask大型教程项目!的教程学习Flask,到了重构用户模型的时候,运行脚本后报错: TypeError: 'bool' object is not callable 这是用户模型: c ...

  2. 【爬坑】Python 3.6 在 Socket 编程时出现类型错误 TypeError: a bytes-like object is required, not 'str'

    1. 问题描述 Python 3.6 在 Socket 编程时出现错误如下 Traceback (most recent call last): File "F:/share/IdeaPro ...

  3. tensorflow:typeerror:‘noneType’ object is not callable

    程序运行报错 typeerror: ‘noneType’ object is not callable 解决方法:删除缓存文件,再次运行没有错误 删除__pycache__文件夹

  4. TypeError: 'bool' object is not callable g.user.is_authenticated()

    此问题查了stackoverflow后知道is_authenticated是一个属性而不是一个方法所以g.user.is_authenticated() 用法会报错

  5. java/javac命令行如何同时引用多个包;错误 TypeError: 'JavaPackage' object is not callable 的含义

    出现这类错误提示:'JavaPackage' object is not callable,可以看下所引用的jar包或者class文件是否在java的路径搜索范围内 命令行模式下:javac可以编译* ...

  6. python import 错误 TypeError: 'module' object is not callable

    python import 错误 TypeError: 'module' object is not callable 在这里,有 Person.py test.py; 在 test.py 里面 im ...

  7. 调用日志输出错误:TypeError: 'int' object is not callable等

    *)TypeError: 'int' object is not callable 错误信息: Traceback (most recent call last): File "Visual ...

  8. python Flask :TypeError: 'dict' object is not callable

    flask 基于Werkzeug .. @moudule.route('/upload', methods=['GET', 'POST']) def upload_file(): global _fl ...

  9. appium 提示报错“TypeError: 'unicode' object is not callable”的解决方式!

    这里提到的这个报错,是小错误且容易经常会犯,有时需要特别注意使用. 目的要求结果:根据某个元素的id值获取到对应id的text值,并且将获取的text值与本身存在的text值做比较,查看text值是否 ...

随机推荐

  1. redis基本操作和在springboot中的使用

    本文介绍redis的使用 redis启动步骤 说明 redis自增自减相关操作 redis string set操作 get操作 其他操作 redis hash set操作 get操作 其他操作 re ...

  2. spring-boot restful put方式提交表单

    使用spring-boot 做接口,如果按restful的路由形式想使用put方式进行表单提交,第一个参数应该为文件参数,代码如下: @PutMapping("/http-put" ...

  3. mysql 存储过程动态执行sql语句

    之前经常在程序中拼接sql语句,其实我们也可以在存储过程中拼接sql 语句,动态的执行~~ 代码如下: DROP PROCEDURE IF EXISTS SearchByDoctor;CREATE P ...

  4. C++风格与C风格文件读写效率测试-vs2015,vs2017

    void test_write() { ; const char* c_plus_write_file = "H://c_plus_write_file.txt"; const c ...

  5. Python函数定义及传参方式

    主要内容:     1.函数初识     2.函数传参方式        (1)位置参数        (2)默认参数        (3)关键参数        (4)非固定传参 一.函数初识 1. ...

  6. Centos手动编译安装vim8

    系统:CentOs6.9 gcc版本:5.1.0 github上拉取vim工程之后,cd src,执行一下命令: $ ./configure $ sudo make gcc -c -I. -Iprot ...

  7. linux系统上部署一个web项目

    对于apache开源项目中tomcat的认识,大多停留在Windows下,这次我通过一个简单的实例来介绍一下在linux下如何搭建tomcat环境,并且部署一个web项目. 先从基本安装开始,可别小看 ...

  8. DEDE 5.7中各函数所在的文件和位置

    /include/taglib/tag.lib.php 2 //function GetTags()/include/payment/yeepay.php 415 function log_resul ...

  9. Ubuntu16 install Anaconda

    gbt@gbt-Precision-7720:~$ gbt@gbt-Precision-7720:~$ cd Anacondagbt@gbt-Precision-7720:~/Anaconda$ gb ...

  10. Sublime Text notes

    1. 设置在窗口右下方显示文件的编码,在user preferences里加上以下的配置 2.设置用新标签页打开新文件而不是用新窗口打开,将以下配置改为false(默认为true)