JourneyJoker/frontend/views.py

28 lines
859 B
Python

from django.shortcuts import redirect, render
from django.utils.translation import LANGUAGE_SESSION_KEY
from django.views.generic import TemplateView
# Create your views here.
class IndexView(TemplateView):
template_name = "frontend/index.html"
def change_language(request):
url = request.GET.get('url', '/')
language = request.GET.get('language', 'de')
if "://" in url:
raise ValueError("This is not a de-referer.")
request.session[LANGUAGE_SESSION_KEY] = language
return redirect(url)
def errorhandler(request, exception, status):
response = render(request, "frontend/error.html", {"status_code": status})
response.status_code = status
return response
def handler404(request, exception):
return errorhandler(request, exception, 404)
def handler500(request):
return errorhandler(request, None, 500)