From 3c38a02896c36e152e9147d50dfd662f9d3e9d64 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 3 Sep 2011 19:16:43 +0200 Subject: [PATCH] requestcontext by error-pages --- openslides/templates/403.html | 25 ------------------------- openslides/templates/404.html | 27 ++------------------------- openslides/templates/500.html | 26 +------------------------- openslides/urls.py | 6 ++++++ openslides/utils/views.py | 16 ++++++++++++++++ 5 files changed, 25 insertions(+), 75 deletions(-) create mode 100644 openslides/utils/views.py diff --git a/openslides/templates/403.html b/openslides/templates/403.html index 99ea3fbdc..f7d59da78 100644 --- a/openslides/templates/403.html +++ b/openslides/templates/403.html @@ -1,31 +1,6 @@ {% extends "base.html" %} {% load tags %} -{% block mainmenu %} - - {% endblock %} - {% block submenu %} {% endblock %} diff --git a/openslides/templates/404.html b/openslides/templates/404.html index 207553df0..0f0a6d328 100644 --- a/openslides/templates/404.html +++ b/openslides/templates/404.html @@ -1,31 +1,8 @@ {% extends "base.html" %} {% load tags %} -{% block mainmenu %} - - {% endblock %} - + + {% block submenu %} {% endblock %} diff --git a/openslides/templates/500.html b/openslides/templates/500.html index fdb3fafc4..8c51a4f9f 100644 --- a/openslides/templates/500.html +++ b/openslides/templates/500.html @@ -1,31 +1,7 @@ {% extends "base.html" %} {% load tags %} -{% block mainmenu %} - - {% endblock %} - + {% block submenu %} {% endblock %} diff --git a/openslides/urls.py b/openslides/urls.py index ee6cb8130..55bb349f8 100644 --- a/openslides/urls.py +++ b/openslides/urls.py @@ -15,6 +15,7 @@ from django.conf import settings from django.contrib import admin admin.autodiscover() +handler500 = 'openslides.utils.views.server_error' urlpatterns = patterns('', (r'^admin/', include(admin.site.urls)), @@ -26,3 +27,8 @@ urlpatterns = patterns('', (r'^static/(?P.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_DOC_ROOT}), (r'^i18n/', include('django.conf.urls.i18n')), ) + + +urlpatterns += patterns('', + (r'^500/$', 'openslides.utils.views.server_error'), +) diff --git a/openslides/utils/views.py b/openslides/utils/views.py new file mode 100644 index 000000000..0d17cfa94 --- /dev/null +++ b/openslides/utils/views.py @@ -0,0 +1,16 @@ +from django.conf import settings +from django.http import HttpResponseServerError +from django.template import Context, loader, RequestContext +from django.template.loader import render_to_string + +def server_error(request, template_name='500.html'): + """ + 500 error handler. + + Templates: `500.html` + Context: + MEDIA_URL + Path of static media (e.g. "media.example.org") + """ + t = loader.get_template("500.html") # You need to create a 500.html template. + return HttpResponseServerError(render_to_string('500.html', context_instance=RequestContext(request)))