/ dashboard /'NoneType'对象上的AttributeError没有属性'year'

时间:2019-04-14 16:04:22

标签: python django

我最近开始使用Django和python处理我的项目,但是我无法解决此问题。请帮忙。以sales_by_months_ts =qss.time_series(start, end, interval='months')开头的行在Django中运行时显示错误。

这是我的回溯错误

File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view
  22.                 return view_func(request, *args, **kwargs)
File "C:\Users\User\Desktop\cbd-master\cbd_project\cbd\views.py" in dashboard
  143.     sales_by_month_ts = qss.time_series(start, end, interval='months')
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\qsstats\__init__.py" in time_series
  70.             return self._fast_time_series(*(args+[engine]))
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\qsstats\__init__.py" in _fast_time_series
  106.         start, _ = get_bounds(start, interval.rstrip('s'))
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\qsstats\utils.py" in get_bounds
  28.     day = _to_datetime(_remove_time(dt))
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\qsstats\utils.py" in _remove_time
  9.     return datetime.datetime(dt.year, dt.month, dt.day, tzinfo=tzinfo)
Exception Type: AttributeError at /dashboard/
Exception Value: 'NoneType' object has no attribute 'year'

我的代码

start, end = mindate['date__min'], maxdate['date__max']
sales_by_month_ts = qss.time_series(start, end, interval='months')
MonthL = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec']
months_dict="["
for t in sales_by_month_ts:
    monthobj_dict="{'month': '"+ t[0].strftime("%Y-%m") + "', 'incidents': '" + str(t[1]) + "'},"
    months_dict = months_dict + monthobj_dict
months_dict = months_dict + "]"

环境

Request Method: GET
Request URL: http://127.0.0.1:8000/dashboard/

Django Version: 1.8.19
Python Version: 3.6.4
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'cbd')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')

0 个答案:

没有答案