Skip to content

Instantly share code, notes, and snippets.

@hirokiky
Created January 2, 2013 09:50
Show Gist options
  • Save hirokiky/4433362 to your computer and use it in GitHub Desktop.
Save hirokiky/4433362 to your computer and use it in GitHub Desktop.
Django's View class to try using a new View.dispatch of this commit https://github.com/hirokiky/django/commit/e3399495dca9a727568626f64e2fa276c2857da9
from django.views.generic import View
from django.http.response import HttpResponse
def corn_predicate(request):
params = getattr(request, request.method)
corn = params.get('corn', None)
return corn == u'1'
class PonyView(View):
dispatch_config = {'get': {'get_corn_1': corn_predicate}}
def get(self, request):
return HttpResponse('pony')
def get_corn_1(self, request):
"""When request has corn=1."""
return HttpResponse('pony with corn')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment