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.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的更多相关文章
- 解决Flask和Django的错误“TypeError: 'bool' object is not callable”
跟着欢迎进入Flask大型教程项目!的教程学习Flask,到了重构用户模型的时候,运行脚本后报错: TypeError: 'bool' object is not callable 这是用户模型: c ...
- 【爬坑】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 ...
- tensorflow:typeerror:‘noneType’ object is not callable
程序运行报错 typeerror: ‘noneType’ object is not callable 解决方法:删除缓存文件,再次运行没有错误 删除__pycache__文件夹
- TypeError: 'bool' object is not callable g.user.is_authenticated()
此问题查了stackoverflow后知道is_authenticated是一个属性而不是一个方法所以g.user.is_authenticated() 用法会报错
- java/javac命令行如何同时引用多个包;错误 TypeError: 'JavaPackage' object is not callable 的含义
出现这类错误提示:'JavaPackage' object is not callable,可以看下所引用的jar包或者class文件是否在java的路径搜索范围内 命令行模式下:javac可以编译* ...
- python import 错误 TypeError: 'module' object is not callable
python import 错误 TypeError: 'module' object is not callable 在这里,有 Person.py test.py; 在 test.py 里面 im ...
- 调用日志输出错误:TypeError: 'int' object is not callable等
*)TypeError: 'int' object is not callable 错误信息: Traceback (most recent call last): File "Visual ...
- python Flask :TypeError: 'dict' object is not callable
flask 基于Werkzeug .. @moudule.route('/upload', methods=['GET', 'POST']) def upload_file(): global _fl ...
- appium 提示报错“TypeError: 'unicode' object is not callable”的解决方式!
这里提到的这个报错,是小错误且容易经常会犯,有时需要特别注意使用. 目的要求结果:根据某个元素的id值获取到对应id的text值,并且将获取的text值与本身存在的text值做比较,查看text值是否 ...
随机推荐
- Spring总结二:IOC(控制反转)xml方式
1,简介: IoC :Inverse of control 控制反转 ,思想就是在项目中引入一个工厂容器,对项目中接口依赖对象的创建,实现项目中对于依赖对象解耦合. 将程序中对象的创建权以及对象的整个 ...
- java基础之io流总结四:字符流读写
字符流读写只适用于字符文件. 基本字符流(转换流)读写文件 转换流本身是字符流,但是实例化的时候传进去的是一个字节流,所以叫做转换流 InputStreamReader isr = new Input ...
- linux 目录和用户权限命令
1.linux 修改文件目录所有者 例:要将当前目录下名 title 的文件夹及其子文件的所有者改为geust组的su用户,方法如下: #chown -R su.geust title -R 递归式地 ...
- 当一个SQL语句同时出现了where,group by,having,order by的时候,执行顺序和编写顺序
当一个查询语句同时出现了where,group by,having,order by的时候,执行顺序和编写顺序 1.执行where xx对全表数据做筛选,返回第1个结果集. 2.针对第1个结果集使用g ...
- SSH连接Linux
转载自百度经验 https://jingyan.baidu.com/article/bea41d439d16d7b4c51be619.html 连接Linux的工具有Putty.SSH Secure ...
- python学习路线以及视频下载
作者:林其链接:https://www.zhihu.com/question/19660572/answer/194904019来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...
- WordPress 4.1去掉侧边栏“功能”小工具中WordPress.Org
打开wp-includes/default-widgets.php,注释掉第398到第403行 echo apply_filters( 'widget_meta_poweredby', sprintf ...
- c语言实践打印字母三角形
效果如下: int main(void) { char ch = 'A';//当前要打印的字符 ;//每行要打印字符的个数 ; i < ; i++,count++) { ; j < cou ...
- 执行CUnit测试出错
est/test_fifo.test: error while loading shared libraries: libcunit.so.1: cannot open shared object f ...
- cakephp中sql查询in
$list = $this->Capital->find('all', array('conditions'=>array('remark in '=>array('银联支付' ...