1👍
✅
Your if statement might return False
and in this case Course_instance
is not defined. You should add exception or an else
branch. I would do it this way:
def attend(request,*args, **kwargs):
request.session.set_expiry(0)
course_id = request.GET.get("course")
if course_id:
course_instance = get_object_or_404(Course_dir, id=course_id)
attend_id, attend = Course_Attendance_sheet.objects.get_or_create(person =request.user, course= course_instance)
attend_id.save()
else:
print('What happened to this course?')
Note that the indentation changed.
Source:stackexchange.com