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

前端 未结 4 668
生来不讨喜
生来不讨喜 2021-01-11 12:49

I\'m having this weird problem.

When I did this:

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


        
4条回答
  •  Happy的楠姐
    2021-01-11 13:16

    This problem is to do with trying to reverse something at import time before the URLs are ready to be reversed. This is not a problem with RedirectView itself - it would happen with anything where you tried to reverse in your urls.py file, or possibly in a file imported by it.

    In the development version of Django, there is a function called reverse_lazy specifically to help in this situation.

    If you're using an earlier version of Django, there is a solution here: Reverse Django generic view, post_save_redirect; error 'included urlconf doesnt have any patterns'.

提交回复
热议问题