I'm not core developer, but I think
http://docs.djangoproject.com/en/dev/topics/http/urls/#defining-url-namespaces
should be used.
you can use reverse("yournamespace:someview"), and it's also cool to
do things like this in settings.py:
reverse_lazy = lazy(reverse, str)
LOGIN_REDIRECT_URL = reverse_lazy('yournamespace:your_main_page')
Perhaps it's not advertised as it should, and people continue to
invent their tricky namespace schemes...
> --
> You received this message because you are subscribed to the Google Groups "Django developers" group.
> To post to this group, send email to django-d...@googlegroups.com.
> To unsubscribe from this group, send email to django-develop...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
>
>
--
Best regards, Yuri V. Baburov, Skype: yuri.baburov, MSN: bu...@live.com
On Tue, Dec 7, 2010 at 6:08 PM, Daniel Swarbrick
<daniel.s...@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?
Simple. In your views.py:
my_view_function = MyViewClass.as_view()
You can then use `my_view_function` like every other view, like using
it in an url pattern without providing a name or decorating it.
But I think we are slowly approaching django-user territory here...
Kind regards,
Benjamin
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
I do this in views.py if want the decorator on all methods (get|post).
myview = login_required(MyView.as_view())