I'm not sure, not having explored CBVs yet, but yes, I suspect you'll
want to either decorate or override the method that usually returns
the HttpResponse.
On Dec 12, 1:50 pm, Eli Criffield wrote:
> I like the raise exception idea, but where do i catch it?
> In a
I like the raise exception idea, but where do i catch it?
In a decorator?
Overwrite get() ?
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-users/-/KMhk4RFokUAJ.
I'd recommend against doing that, as it's a strong violation of MVC
principles. Instead you should either catch the
ModelName.DoesNotExist exception in a custom (or inherited, or generic-
view-wrapping) view, or raise a custom exception in your get_queryset
method and catch that exception
I faced a similar situation where I had to check for valid input data
used to build the query in get_queryset(). My solution was to use a
decorator around the dispatch() function, but I think it could also be
used within that function. I chose dispatch() because it acts like a
traditional view
So in a class based view inheriting generic.ListView I want to redirect on
a condition, The logical place to do it is get_queryset, but you can't go
returning a HttpResponseRedirect from a method that should return a query
set. The django.shortcuts.redirect() just kinda does that for you so
5 matches
Mail list logo