Skip to content

Instantly share code, notes, and snippets.

@patrys
Last active December 20, 2016 18:57
Show Gist options
  • Save patrys/63cb08ec0363267011739fa28296179a to your computer and use it in GitHub Desktop.
Save patrys/63cb08ec0363267011739fa28296179a to your computer and use it in GitHub Desktop.
from django.template.response import TemplateResponse
from django.views.generic import View
class MyClassBasedView(View):
def __init__(self, foo='bar'):
self._foo = foo
def get(self, request):
context = {'foo': self._foo}
return TemplateResponse(request, 'index.html', context)
my_class_based_view = MyClassBasedView.as_view(foo='bar')
# TypeError: MyClassBasedView() received an invalid keyword 'foo'.
# as_view only accepts arguments that are already attributes of the class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment