Need a view that takes an idea from the context and returns redirect url.
This code works fine:
class FooView(RedirectView):
def get(self, request, id, *args, **kwargs):
...
return HttpResponseRedirect(reverse('foo_space:foo', urlconf='bar.system.urls'))
Definitely worthwhile. Check out what RedirectView
does. For one, it redirects all methods by default PUT
, POST
, HEAD
etc. while View
would throw a 405
for everything but get
And definitely override get_redirect_url
to take advantage of the above.
It could be simpler via setting the pattern_name
attribute only, but it looks like you need the urlconf
kwarg as well so this method may not work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.