我的Django项目中的以下代码有问题。 有人知道这是怎么回事吗?
异常类型:/ tasks / 2/3 /处的TypeError异常值:int()参数必须是字符串,类似字节的对象或数字,而不是'DeferredAttribute'
(Django 2.1)
def step_detail(request, task_pk, step_pk):
user = request.user
steps = Step.objects.filter(task_id=task_pk)
step = get_object_or_404(Step, task_id=task_pk, pk=step_pk)
next = ""
if int(Step.step_number) < len(steps):
next = "/%s/%s/" % (task_pk, int(step_pk) + 1)
user.userprofile.current_step.update(step_pk)
else:
next = "/task_done/"
user.userprofile.current_step.update(step_pk)
user.userprofile.daily_task_done_time(datetime.datetime.now())
if request.POST:
if "nextstep" in request.POST:
return redirect(request.POST.get('next'))
return render(request, 'dailytask/step_detail.html', {'step': step})
环境:
请求方法:GET请求URL:http://127.0.0.1:8000/tasks/2/3/
Django版本:2.1.1 Python版本:3.7.1已安装的应用程序: ['django.contrib.admin','django.contrib.auth', 'django.contrib.contenttypes','django.contrib.sessions', 'django.contrib.messages','django.contrib.staticfiles', 'dailytask','account']已安装的中间件: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware']
跟踪:
文件 “ /Users/iamsuccessful/eb-virt/lib/python3.7/site-packages/django/core/handlers/exception.py” 在内部 34. response = get_response(request)
文件 “ /用户/成功/eb-virt/lib/python3.7/site-packages/django/core/handlers/base.py” 在_get_response中 126. response = self.process_exception_by_middleware(e,request)
文件 “ /用户/成功/eb-virt/lib/python3.7/site-packages/django/core/handlers/base.py” 在_get_response中 124. response = wrapd_callback(request,* callback_args,** callback_kwargs)
文件 “ /Users/iamsuccessful/eb-virt/lib/python3.7/site-packages/django/contrib/auth/decorators.py” 在_wrapped_view中 21. return view_func(request,* args,** kwargs)
step_detail中的文件“ /Users/iamsuccessful/ebdjango/dailytask/views.py” 60. if int(Step.step_number)
异常类型:/ tasks / 2/3 /处的TypeError异常值:int() 参数必须是字符串,类似字节的对象或数字,而不是 'DeferredAttribute'