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 imported app.urls
  • app.urls imported app.views
  • app.views had a class-based view that used reverse
  • reverse imports project.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?


IN my case I got this error during deployment. Apache kept giving me the "AH01630: client denied by server configuration" error. This indicated that was wrong with apache configuration. To help troubleshoot I had turned on Debug=True in settings.py when I saw this error.

In the end I had to add a new directive to the static files configuration inside apache config. When the static files were not accessible and Debug in django settings was set to true this error was getting triggered somehow.

Tags:

Python

Django