django - Django TypeError:未提供异常消息
问题描述
我在理解此错误消息时遇到问题..
我在视图中写了这行代码
qs = Stockdata.objects.filter(User=self.request.user, Company=company_details.pk, Date__gte=selectdatefield_details.Start_Date, Date__lte=selectdatefield_details.End_Date)
total = qs.annotate(Sum('salestock__Quantity'))['the_sum']
total2 = qs.annotate(Sum('purchasestock__Quantity_p'))['the_sum']
tqty = total2 - total
context['Totalquantity'] = tqty
context['Totalquantitysales'] = total
context['Totalquantitypurchase'] = total2
有人知道我在代码中做错了什么吗?
谢谢
追溯:
Traceback:
File "C:\Users\HP\myEnv\lib\site-packages\django\core\handlers\exception.py" in inner
35. response = get_response(request)
File "C:\Users\HP\myEnv\lib\site-packages\django\core\handlers\base.py" in _get_response
128. response = self.process_exception_by_middleware(e, request)
File "C:\Users\HP\myEnv\lib\site-packages\django\core\handlers\base.py" in _get_response
126. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\HP\myEnv\lib\site-packages\django\views\generic\base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "C:\Users\HP\myEnv\lib\site-packages\django\contrib\auth\mixins.py" in dispatch
52. return super().dispatch(request, *args, **kwargs)
File "C:\Users\HP\myEnv\lib\site-packages\django\views\generic\base.py" in dispatch
89. return handler(request, *args, **kwargs)
File "C:\Users\HP\myEnv\lib\site-packages\django\views\generic\list.py" in get
157. context = self.get_context_data()
File "C:\Users\HP\My Documents\github\erpcloud\erpcloud\stockkeeping\views.py" in get_context_data
446. total = qs.annotate(Sum('salestock__Quantity'))['the_sum']
File "C:\Users\HP\myEnv\lib\site-packages\django\db\models\query.py" in __getitem__
282. raise TypeError
Exception Type: TypeError at /stockkeeping/company/31/date/13/
Exception Value:
解决方案
错误是您无法从Queryset
对象中按键获取值
阅读更多关于Django 中的注解
推荐阅读
- reporting-services - SSRS 服务器的登陆页面或错误 html 页面
- php - 使用 php 从远程服务器在 ejabberd(本地主机上)上注册用户
- sql - 动态排序和按列排序
- math - Mandelbrot Set - 颜色光谱建议?
- nixos - fetchFromGitHub,过滤下来作为 environment.etc."file".source
- c# - MSMQ MessageQueue.BeginReceive(时间跨度,对象)
- mysql - 为什么SQL中的结果总和与原始数据的结果不兼容?
- ios - 在不同的单元格笔尖中显示 2 组 Firebase 数据
- security - Jenkins 从 2.154 降级回 2.152 后无法登录
- python - 在jupyter中打开时无法查看文件夹中的,ipynb文件