Browse files

[1.5.X] Clarified usage of as_view kwargs for setting arguments on cl…

…ass based views

Thanks Dave McLain for the patch.

Backport of 7b2d95e from master
  • Loading branch information...
1 parent 74e22f9 commit 63546533c1fd7cfe003140bbe15a7d465aa787eb @timgraham timgraham committed Nov 22, 2012
Showing with 6 additions and 4 deletions.
  1. +3 −2 django/views/generic/
  2. +3 −2 docs/ref/class-based-views/index.txt
@@ -54,8 +54,9 @@ def as_view(cls, **initkwargs):
"keyword argument to %s(). Don't do that."
% (key, cls.__name__))
if not hasattr(cls, key):
- raise TypeError("%s() received an invalid keyword %r" % (
- cls.__name__, key))
+ raise TypeError("%s() received an invalid keyword %r. as_view "
+ "only accepts arguments that are already "
+ "attributes of the class." % (cls.__name__, key))
def view(request, *args, **kwargs):
self = cls(**initkwargs)
@@ -37,10 +37,11 @@ A class-based view is deployed into a URL pattern using the
is modified, the actions of one user visiting your view could have an
effect on subsequent users visiting the same view.
-Any argument passed into :meth:`~django.views.generic.base.View.as_view()` will
+Arguments passed into :meth:`~django.views.generic.base.View.as_view()` will
be assigned onto the instance that is used to service a request. Using the
previous example, this means that every request on ``MyView`` is able to use
+``self.size``. Arguments must correspond to attributes that already exist on
+the class (return ``True`` on a ``hasattr`` check).
Base vs Generic views

0 comments on commit 6354653

Please sign in to comment.