Trying to check if variable 'avail.end_time:' is empty,and if so redirect to a url. But instead, I get "The view mysite.views.enter_queue didn't return an HttpResponse object. It returned None instead." ERROR
Endtime variable is being referenced from my Availabilities model where end_time = models.TimeField(null=False, blank=False)
I know this questions been asked before but none of the solutions given have helped solve the problem.
@login_required
def enter_queue(request):
# get the user from the Django request & map to variable
django_user = request.user
#link user_profile to django users profile model & get user's profile
user_profile = django_user.profile
#user_profile = Profile.objects.get(user=request.user)
#Map user_availabilities variable to profile from Availability model
users_availabilities = Availability.objects.filter(profile=user_profile)
#mapping user_avail to user profile
#creating an array to store all matching sessions
all_matching_sessions = []
# avail is each Availability object
for avail in users_availabilities:
if avail.end_time:
return HttpResponseRedirect(render(request,'mysite/profile.html'))
else:
matching_sessions = Session.objects.filter(end_time__lte=avail.end_time)#looping through all the sessions end times that match to availability
#adding them to the array
all_matching_sessions = all_matching_sessions + matching_sessions
#If no matching sessions are available
if len(all_matching_sessions) == 0:
#create a session
player_session = Session(
game = 'random_game',
start_time = users_availabilities[0].start_time,
end_time = users_availabilities[0].end_time,
)
player_session.save()
return render(request, 'mysite/profile.html')
else:
player_session = Session(
session = all_matching_sessions[0],
profile = user_profile
)
player_session.save()
#return HttpResponse('Waiting in queue')
return render(request, 'mysite/profile.html')
Image of the error for reference
**ERROR*
ValueError at /account/enter_queue/
The view mysite.views.enter_queue didn't return an HttpResponse object. It
returned None instead.
Request Method: GET
Request URL: http://127.0.0.1/account/enter_queue/
Django Version: 2.0.3
Exception Type: ValueError
Exception Value:
The view mysite.views.enter_queue didn't return an HttpResponse object. It
returned None instead.
Exception Location: /usr/local/lib/python3.6/site-
packages/django/core/handlers/base.py in _get_response, line 139
Python Executable: /usr/local/bin/python3.6
Python Version: 3.6.4
Python Path:
['/home/mihir/meshwell/capstone-project/siteroot',
'/usr/local/lib/python36.zip',
'/usr/local/lib/python3.6',
'/usr/local/lib/python3.6/lib-dynload',
'/usr/local/lib/python3.6/site-packages',
'/var/www/CapstoneProject/siteroot',
'/var/www/CapstoneProject/siteroot/mysite']
Server time: Thu, 5 Apr 2018 04:07:23 +0000
Traceback Switch to copy-and-paste view
/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py in
inner
response = get_response(request)
...
▶ Local vars
/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py in _get_response
"returned None instead." % (callback.__module__, view_name)
...
▶ Local vars