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.

Leave a Comment