diff options
-rw-r--r-- | askbot/setup_templates/urls.py | 8 | ||||
-rw-r--r-- | askbot/urls.py | 4 | ||||
-rw-r--r-- | askbot/views/error.py | 16 |
3 files changed, 24 insertions, 4 deletions
diff --git a/askbot/setup_templates/urls.py b/askbot/setup_templates/urls.py index ea6e3905..22847a3f 100644 --- a/askbot/setup_templates/urls.py +++ b/askbot/setup_templates/urls.py @@ -3,11 +3,13 @@ main url configuration file for the askbot site """ from django.conf import settings try: - from django.conf.urls import handler404, handler500 + from django.conf.urls import handler404 from django.conf.urls import include, patterns, url except ImportError: - from django.conf.urls.defaults import handler404, handler500 + from django.conf.urls.defaults import handler404 from django.conf.urls.defaults import include, patterns, url + +from askbot.views.error import internal_error as handler500 from django.conf import settings from django.contrib import admin @@ -41,3 +43,5 @@ if 'rosetta' in settings.INSTALLED_APPS: urlpatterns += patterns('', url(r'^rosetta/', include('rosetta.urls')), ) + +handler500 = 'askbot.views.error.internal_error' diff --git a/askbot/urls.py b/askbot/urls.py index 566173ce..799ef0f5 100644 --- a/askbot/urls.py +++ b/askbot/urls.py @@ -7,10 +7,10 @@ from django.conf import settings try: from django.conf.urls import url, patterns, include - from django.conf.urls import handler500, handler404 + from django.conf.urls import handler404 except ImportError: from django.conf.urls.defaults import url, patterns, include - from django.conf.urls.defaults import handler500, handler404 + from django.conf.urls.defaults import handler404 from django.contrib import admin from askbot import views diff --git a/askbot/views/error.py b/askbot/views/error.py new file mode 100644 index 00000000..827e2240 --- /dev/null +++ b/askbot/views/error.py @@ -0,0 +1,16 @@ +from django.http import HttpResponseServerError +from django.template import RequestContext +from django.template.loader import get_template + +def internal_error(request): + """Error 500 view with context""" + template = get_template('500.html') + try: + result = template.render(RequestContext(request)) + except Exception: + #if context loading fails, we try to get settings separately + from askbot.conf import settings as askbot_settings + data = {'settings': askbot_settings.as_dict()} + result = template.render(RequestContext(request, data)) + + return HttpResponseServerError(result) |