I want to fill out the success_url
of a django form view using a named url:
class RegisterView(generic.edit.FormView):
template_name = "cmmods/register.html"
form_class = RegisterForm
#success_url = reverse('complete-registration')
success_url = "/cmmods/complete-registration"
When I type the URL explicitly, as uncommented above, it works.
When I try to do a reverse lookup of the url (currently commented out, above) , I get:
The included urlconf 'cm_central.urls' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
I guess it's clear that my urls.py is actually valid (does have patterns in it), since the uncommented version of the code works.
How should I be doing this?
That means the dependency has not been loaded yet. You can use reverse_lazy
to defer the evaluation of the url pattern
Like this:
success_url = reverse_lazy('complete-registration')
Documentation of reverse_lazy
can be found here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With