Skip to content

Instantly share code, notes, and snippets.

@victorono
Last active December 31, 2015 18:39
Show Gist options
  • Save victorono/8028349 to your computer and use it in GitHub Desktop.
Save victorono/8028349 to your computer and use it in GitHub Desktop.
middleware for display page when method is not allowed https://docs.djangoproject.com/en/1.2/topics/http/decorators/#allowed-http-methods
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.http import HttpResponseNotAllowed
from django.template import RequestContext
from django.template import loader
class HttpResponseNotAllowedMiddleware(object):
def process_response(self, request, response):
if isinstance(response, HttpResponseNotAllowed):
context = RequestContext(request)
response.content = loader.render_to_string("app/error_405.html", context_instance=context)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment