Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Django's RedirectView with a named url

I'm trying to make my a_detail redirect to my a_detail_slug url. I want to use the named url for this but I haven't succeeded yet, this is what I've tried:

url(r'^a/(?P<pk>\d+)/(?P<filler>[\w-]+)/$', AList.as_view(template_name="a.html"), name="a_detail_slug"),

url(r'^a/(?P<pk>\d+)/$', RedirectView.as_view(url=reverse_lazy("a_detail_slug"),), name="a_detail"),

This is meant to catch any link with a valid pk and redirect to that page with an appended filler.

like image 828
vascop Avatar asked Jan 17 '23 21:01

vascop


1 Answers

a_detail_slug requires 2 params (pk and filler) but you pass none of them. The easiest way will be extend RedirectView:

class ARedirect(RedirectView):
    def get_redirect_url(self, pk):
        filler = get_filler_somehow()
        return reverse('a_detail_slug', args=(pk, filler))
like image 116
San4ez Avatar answered Jan 26 '23 07:01

San4ez