courses.models.DoesNotExist: Course matching query does not exist.
来源:10-10 我的收藏功能2
慕码人8817864
2018-06-02
老师,在个人中心,我收藏的课程,报这个错
Internal Server Error: /users/myfav/course/
Traceback (most recent call last):
File "C:\Users\1\Envs\eduonline\lib\site-packages\django\core\handlers\base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\1\Envs\eduonline\lib\site-packages\django\core\handlers\base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\1\Envs\eduonline\lib\site-packages\django\views\generic\base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Users\1\Envs\eduonline\lib\site-packages\django\utils\decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "C:\Users\1\Envs\eduonline\lib\site-packages\django\contrib\auth\decorators.py", line 23, in _wrapped_view
return view_func(request, *args, **kwargs)
File "C:\Users\1\Envs\eduonline\lib\site-packages\django\utils\decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "C:\Users\1\PycharmProjects\EduOnline\apps\utils\mixin_util.py", line 13, in dispatch
return super(LoginRequiredMixin, self).dispatch(request,*args,**kwargs)
File "C:\Users\1\Envs\eduonline\lib\site-packages\django\views\generic\base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "C:\Users\1\PycharmProjects\EduOnline\apps\users\views.py", line 298, in get
course = Course.objects.get(id=course_id)
File "C:\Users\1\Envs\eduonline\lib\site-packages\django\db\models\manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\1\Envs\eduonline\lib\site-packages\django\db\models\query.py", line 387, in get
self.model._meta.object_name
courses.models.DoesNotExist: Course matching query does not exist.
1回答
-
bobby
2018-06-04
File "C:\Users\1\PycharmProjects\EduOnline\apps\users\views.py", line 298, in get
course = Course.objects.get(id=course_id)
这行代码没有查询到course 建议你使用filter方法 你可以用try catch特殊处理一下
00
相似问题