On 7 December 2010 18:08, Daniel Swarbrick <daniel.swarbr...@gmail.com> wrote:
> Forgetting namespaces or existing named URL patterns for a moment, the
> major difference is that with function-based views, we were giving a
> qualified "module.function" parameter to reverse() or {% url %}.
>
> How can we do that with class-based views, without naming every URL
> pattern? Or is it not possible?

A similar question was asked here:
http://groups.google.com/group/django-users/browse_frm/thread/847758c4f554c5b9/dee7ebf13296d1ec

It's not possible without extra work. But if you're already doing
extra work, you can just name the view and be nice to people who will
reuse your application. I currently use "<app>-<model>_<action>"
scheme in my projects.

>
> A side question that's been nagging at me during all this is, will
> class-based views become the norm, even in places where we weren't
> using function-based generic views? I was using direct_to_template()
> in 99% of my views, simply because it was a shortcut for the whole
> render_to_response('my_template.html', my_data_dictionary,
> context_instance=RequestContext(request)) palaver. In most cases I was
> still passing an extra_context, but it was a little bit less
> typing ;-)

Your anwser here is the code that was commited today:
http://code.djangoproject.com/changeset/14850
TemplateResponse replaces direct_to_template as a shortcut. CBVs
aren't meant to replace function-views entriely. They are mainly
targeted at generic views and reusable applications.

>
> Another question (sorry - maybe these should be separate posts), how
> does one go about using the permission_required() decorator with class-
> based views, or something like the following:
>
> @user_passes_test(lambda u: u.is_superuser)
> def my_superview(request):
>    ...
>    return response
>
> Sorry if I'm jumping the gun a little bit. I realise this is a dev
> version and is still in flux.

This is in the docs:
http://docs.djangoproject.com/en/dev/topics/class-based-views/#decorating-class-based-views

PS. As Benjamin already mentioned, I think we're in django-users land now.

-- 
Łukasz Rekucki

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to