Django - The included urlconf doesn't have any patterns in it
TL;DR: You probably need to use reverse_lazy()
instead of reverse()
If your urls.py
imports a class-based view that uses reverse()
, you will get this error; using reverse_lazy()
will fix it.
For me, the error
The included urlconf project.urls doesn't have any patterns in it
got thrown because:
-
project.urls
importedapp.urls
-
app.urls
importedapp.views
-
app.views
had a class-based view that usedreverse
-
reverse
importsproject.urls
, resulting in a circular dependency.
Using reverse_lazy
instead of reverse
solved the problem: this postponed the reversing of the url until it was first needed at runtime.
Moral: Always use reverse_lazy
if you need to reverse before the app starts.
Check your patterns for include statements that point to non-existent modules or modules that do not have a urlpatterns
member. I see that you have an include('urls.ajax')
which may not be correct. Should it be ajax.urls
?
check for correct variable name in your app, if it is "
urlpatterns
" or any thing else. Correcting name helped me