added 404 catching if no assignment exists

parent 12ef1b9d
from django.shortcuts import render
from .models import Assignment, Course
from django.http import Http404
def ListView_view(request, *args, **kwargs):
......@@ -10,7 +11,10 @@ def ListView_view(request, *args, **kwargs):
def DetailView_view(request, pk):
detailed_context = {
"assignment": Assignment.objects.get(id=pk)
}
return render(request, "assignments/DetailView.html", detailed_context)
if Assignment.objects.filter(id=pk).exists():
detailed_context = {
"assignment": Assignment.objects.get(id=pk)
}
return render(request, "assignments/DetailView.html", detailed_context)
else:
raise Http404('Assignment does not exist.')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment