add 404 rule for misspelled countries

This commit is contained in:
koksnuss 2020-05-01 23:25:17 +02:00
parent 0e9ef03031
commit c6fd777ca0

View File

@ -20,7 +20,7 @@
from datetime import datetime from datetime import datetime
from json import dumps from json import dumps
from django.http import HttpResponse from django.http import HttpResponse, Http404
from django.template import loader from django.template import loader
from django.template.defaultfilters import register from django.template.defaultfilters import register
@ -45,7 +45,11 @@ def detail_country(request, name_iso):
''' wrapper_view for a *single* country ''' ''' wrapper_view for a *single* country '''
template = loader.get_template('coinc/country.html') template = loader.get_template('coinc/country.html')
try:
country = Country.objects.get(name_iso=name_iso) country = Country.objects.get(name_iso=name_iso)
except Country.DoesNotExist:
raise Http404(f"Das Land '{name_iso}' ist nicht vorhanden")
context = show_country(country, single_country=True) context = show_country(country, single_country=True)
return HttpResponse(template.render(context, request)) return HttpResponse(template.render(context, request))