Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django RedirectView and reverse() doesn't work together?

Tags:

python

django

I'm having this weird problem.

When I did this:

from django.core.urlresolvers import reverse
reverse('account-reco-about-you')
# returns '/accounts/recommendations/about-you/'

But when I did this:

# Doesn't Work
recommendations = login_required(RedirectView.as_view(url=reverse('account-reco-about-you')))

# Work
recommendations = login_required(RedirectView.as_view(url='/accounts/recommendations/about-you'))

Error message I get if unrelated. It says my last view is not found, which is there. Any explanation? Meantime, i'll make do with the non-reverse style.

like image 265
Mickey Cheong Avatar asked Aug 28 '11 01:08

Mickey Cheong


1 Answers

no need for reverse() or reverse_lazy().

simply specify the pattern_name parameter:

RedirectView.as_view(pattern_name='account-reco-about-you')
like image 68
captnswing Avatar answered Oct 19 '22 20:10

captnswing