[Django]-Trying to trace a circular import error in Django

20👍

Try changing

urlpatterns = [
     url(r'^accounts/', include('accounts_app')),
] 

to

urlpatterns = [
     url(r'^accounts/', include('accounts_app.urls')), # add .urls after app name
]

59👍

for those who have the same error but still hasn’t debugged their code, also check how you typed “urlpatterns”

having it mistyped or with dash/underscore will result to the same error

8👍

Those habitual with CamelCased names may face the error as well.

urlpatterns has to be typed exactly as ‘urlpatterns’

This will show you error –

urlPatterns = [
    path('', views.index, name='index'),

Error –

django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'polls.urls' from '...\\polls\\urls.py'>' 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.

However, fixing the CamelCase will work –

urlpatterns = [
    path('', views.index, name='index'),
]

8👍

After 1 hour search it appears that it’s wrong speelling it should be : urlpatterns

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

2👍

In my case, I got this error because I called the reverse function for a url that required a slug parameter without placing the correct parameter in it.

Once I fixed the reverse function, it was resolved.

1👍

In my case I was getting error because I was giving wrong path of dir containing urls. So I changed this

urlpatterns = [
    url(r'^user/', include('core.urls'))
]

to this

urlpatterns = [
    url(r'^user/', include('core.urls.api'))
]

1👍

In my case i was getting this error because i was typing urlpatterns in urls.py to urlpattern.

0👍

This error also appears if SomeView doesn’t exist in views.py and you do this:

from someapp import views

urlpatterns = [
    path('api/someurl/', views.SomeView.as_view(), name="someview"),
]

So make sure all Views you use in urls.py exist in views.py

👤DevB2F

0👍

In my case, I was getting

/SLMS_APP1/urls.py’>’ 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 made a typo in ‘urlpatter’

urlpatter = [
path(”,views.index, name=’index’),

]

where in correct spelling has to be ‘urlpatterns’

urlpatterns = [
path(”,views.profile, name=’profile’),

]

0👍

this error basically occurs when you have, include the app in the main urls.py file and haven’t declared urlpattern= [] in-app file.

0👍

In my case I changed "reverse" for "reverse_lazy" on my success_url and magially it works.

0👍

I changed this…

app_name='users'
urlpatterns=(
    path('signup/', SignupView.as_view(),name='signup')
)

to this…

app_name='users'
urlpatterns=(
    path('signup/', SignupView.as_view(),name='signup'),
)

notice the last COMMA

Leave a comment