Django "No Patterns" / Circular Import Error

Viewed 711

I've scoured all of the issues I can find about this error and tried all of the solutions, yet none (save one; more on that later) worked for me. Every time I start up my app, I get the following error:

django.core.exceptions.ImproperlyConfigured: The included URLconf 'gamerank.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've checked my files for circular imports, and cannot find any at all.

  1. voting/urls.py only imports voting/views.py
  2. voting/views.py imports voting/models.py, voting/helpers.py, and voting/forms.py
  3. voting/models.py imports from libraries only
  4. voting/helpers.py imports from libraries only
  5. voting/forms.py imports from voting/models.py (which does not import from voting/forms.py)

This answer works for me, but I cannot access any of my application after that (because I just commented out the routes), so it's not really a solution in my case.

Here are some of my files:

voting/urls.py

from django.urls import path

from . import views

app_name = 'voting'
urlpatterns = [
    path('', views.index, name="index"),

    # auth routes
    path("login", views.login_view, name="login"),
    path("logout", views.logout_view, name="logout"),
    path("register", views.register, name="register")
]

gamerank/urls.py

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('voting.urls')),
]

1 Answers

Turns out I was attempting to run reverse in a module that would cause circular import. The solution was to use reverse_lazy as suggested in the comments.

Related