Thursday, February 28, 2013

Re: Wording in Djang Docs: "per instance" vs "every instance"

> This approach applies the decorator on a per-instance basis. If you want
> every instance of a view to be decorated, you need to take a different
> approach.

This means that with "this approach" you have to apply the decorator
in every instance you want modified, that is, every time you have this

url(<pattern>, YourView.as_view(),...)

and want it decorated, you need to wrap it, individually, like

url(<pattern>, decorator(YourView.as_view()), ....)

and if you want to define the entire view as decorated, so you don't
need to decorate it every time you use it in an urlpattern, because it
ALWAYS needs, e.g., to be login_required, you'll need to take a
different approach.

With function views, this was the normal case, because you did

@decorator
def my_view(request, *args, **kwargs):
......

and you didn't need to add anything in the urls, with class-based
views, you need to do this:
https://docs.djangoproject.com/en/1.5/topics/class-based-views/intro/#decorating-the-class


--
"The whole of Japan is pure invention. There is no such country, there
are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment