'tuple' 对象没有属性 'is_preview'
'tuple' object has no attribute 'is_preview'
我正在做一个项目,用户可以在其中创建视频并检查是否可以在购买前预览特定内容,到目前为止一切正常,我得到了这个 'tuple' object has no attribute 'is_preview'
我不能真正告诉这个错误是从哪里来的。
这也是回溯指向的地方
回溯
Traceback (most recent call last):
File "C:\Users\Destiny\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\Destiny\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Destiny\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File "C:\Users\Destiny\Desktop\DexxaEd\dnextedprj\course\views.py", line 122, in course_details
if(video.is_preview is False):
AttributeError: 'tuple' object has no attribute 'is_preview'
[01/May/2022 20:08:43] "GET /course/et-ea-velit-ad-veritatis-explicabo HTTP/1.1" 500 73905
views.py 第 122 行
if serial_number is None:
serial_number = 1
# if Video.objects.all().exists
video = Video.objects.get_or_create(serial_number=serial_number, course=course)
video_count = Video.objects.get(serial_number=serial_number, course=course)
if(video.is_preview is False):
if request.user.is_authenticated is False:
return redirect("course:sign-in")
else:
user = request.user
try:
user_course = UserCourse.objects.get(user=user, course=course)
except:
return redirect("course:check-out", slug=course.slug)
form.py
CourseVideosFormset = inlineformset_factory(Course, Video, fields=('title','serial_number', 'video_id', 'is_preview'))
.get_or_create(…)
[Django-doc] returns 一个二元组,对象 created/retrieved 作为第一项,布尔值是 True
以防对象被创建为第二项。你因此解压这些:
<strong>video, __</strong> = Video.objects.get_or_create(serial_number=serial_number,
我正在做一个项目,用户可以在其中创建视频并检查是否可以在购买前预览特定内容,到目前为止一切正常,我得到了这个 'tuple' object has no attribute 'is_preview'
我不能真正告诉这个错误是从哪里来的。
这也是回溯指向的地方 回溯
Traceback (most recent call last):
File "C:\Users\Destiny\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\Destiny\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Destiny\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File "C:\Users\Destiny\Desktop\DexxaEd\dnextedprj\course\views.py", line 122, in course_details
if(video.is_preview is False):
AttributeError: 'tuple' object has no attribute 'is_preview'
[01/May/2022 20:08:43] "GET /course/et-ea-velit-ad-veritatis-explicabo HTTP/1.1" 500 73905
views.py 第 122 行
if serial_number is None:
serial_number = 1
# if Video.objects.all().exists
video = Video.objects.get_or_create(serial_number=serial_number, course=course)
video_count = Video.objects.get(serial_number=serial_number, course=course)
if(video.is_preview is False):
if request.user.is_authenticated is False:
return redirect("course:sign-in")
else:
user = request.user
try:
user_course = UserCourse.objects.get(user=user, course=course)
except:
return redirect("course:check-out", slug=course.slug)
form.py
CourseVideosFormset = inlineformset_factory(Course, Video, fields=('title','serial_number', 'video_id', 'is_preview'))
.get_or_create(…)
[Django-doc] returns 一个二元组,对象 created/retrieved 作为第一项,布尔值是 True
以防对象被创建为第二项。你因此解压这些:
<strong>video, __</strong> = Video.objects.get_or_create(serial_number=serial_number,