Skip to content

Commit

Permalink
Merge pull request #544 from benjaoming/testproject-layout
Browse files Browse the repository at this point in the history
Amendment to modernization of testproject
  • Loading branch information
benjaoming committed May 5, 2016
2 parents 1a37f15 + a2792ff commit adcfdb4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
11 changes: 7 additions & 4 deletions testproject/testproject/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
"django.template.context_processors.request",
"django.template.context_processors.tz",
"django.contrib.messages.context_processors.messages",
"sekizai.context_processors.sekizai",
],
'debug': DEBUG,
},
Expand Down
3 changes: 3 additions & 0 deletions testproject/testproject/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@
url(r'^notify/', get_notify_pattern()),
url(r'', get_wiki_pattern())
]

handler500 = 'testproject.views.server_error'
handler404 = 'testproject.views.page_not_found'
24 changes: 24 additions & 0 deletions testproject/testproject/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.conf import settings
from django.http import HttpResponseServerError
from django.template import loader
from django.template.context import RequestContext
from django.views.decorators.csrf import requires_csrf_token


@requires_csrf_token
def server_error(request, template_name='500.html'):
# You need to create a 500.html template.
t = loader.get_template(template_name)
return HttpResponseServerError(t.render(RequestContext(
request,
{
'MEDIA_URL': settings.MEDIA_URL,
'STATIC_URL': settings.STATIC_URL,
},
)))


def page_not_found(request, template_name='404.html'):
response = server_error(request, template_name=template_name)
response.status_code = 404
return response

0 comments on commit adcfdb4

Please sign in to comment.