社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Django

如何在django视图中进行加法?

Mossaddak Sium • 4 年前 • 2053 次点击  

当我去添加多个整数变量时,我得到了下面的错误。现在,我们该怎么办?

错误:

TypeError at /
unsupported operand type(s) for +: 'method' and 'int'
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 3.2.3
Exception Type: TypeError
Exception Value:    
unsupported operand type(s) for +: 'method' and 'int'

意见:

total_frontend_order = request.user.user_frontend_order.all().count
total_backend_order = request.user.user_backend_order.all().count
total_complete_website_order = request.user.user_complete_website_order.all().count
a = total_frontend_order+1
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/130770
文章 [ 2 ]  |  最新文章 4 年前
Willem Van Onsem
Reply   •   1 楼
Willem Van Onsem    4 年前

你需要 呼叫 这个 .count() method [Django-doc]

total_frontend_order = request.user.user_frontend_order.all().count()
total_backend_order = request.user.user_backend_order.all().count()
total_complete_website_order = request.user.user_complete_website_order.all().count()
a = total_frontend_order+1
TeRe
Reply   •   2 楼
TeRe    4 年前

你需要写count() 带括号。