我的代码有问题。返回"AttributeError: 'NoneType' object has no attribute 'extraBottles'"
的错误日志
Internal Server Error: /employee/order/79/
Traceback (most recent call last):
File "/mnt/c/Users/davep/Desktop/a/Water_management/newenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/mnt/c/Users/davep/Desktop/a/Water_management/newenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/mnt/c/Users/davep/Desktop/a/Water_management/newenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/mnt/c/Users/davep/Desktop/a/Water_management/employee/views.py", line 44, in view_order
day_.extraBottles += request.session['extraBottles']
AttributeError: 'NoneType' object has no attribute 'extraBottles'
1条答案
按热度按时间mspsb9vt1#
您的day_ object为None,因此当您尝试访问extraBottles属性时,它会抛出错误。在尝试访问day对象的属性或使用getattr函数之前,应该检查day对象是否不是None。