25

I understand circular import error has been asked about a lot but after going through these questions I haven't been able to solve my issue. When I try to run my server in Django its giving me this error message:

The included URLconf module 'accounts_app' from path\to\myproject\__init__.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.

The issue started when i added a new app which has a urls.py like the following

from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^signin$', views.signin, name='signin'),
    url(r'^signout$', views.signout, name='signout'),
    url(r'^signup$', views.signup, name='signup'),
]

My project urls.py has a line which points to the app and looks like the following code

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

My view looks like the following:

from django.shortcuts import render
from django.http import HttpResponse

def signin(request):
    return HttpResponse("<p>This the signin view</p>")

def signout(request):
    return HttpResponse("<p>This the signout view</p>")

def signup(request):
    return HttpResponse("<p>This the signup view</p>")

Can anyone please help me identify were I could possibly be going wrong.

1
  • To find the circular dependency just inspect the backtrace.
    – x-yuri
    Sep 17, 2019 at 13:37

12 Answers 12

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

3
  • 2
    thak you very much. missing N in urlpatterns made me lost 5 hours. Apr 17, 2020 at 22:16
  • 1
    Thank you so much, this took 5 minutes to hunt down thanks to your answer instead of 5 hours! Apr 30, 2020 at 19:30
  • 1
    or misnaming it urlPatterns instead of all lowercase
    – foamroll
    Jul 7, 2020 at 23:41
20

Try changing

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

to

urlpatterns = [
     url(r'^accounts/', include('accounts_app.urls')), # add .urls after app name
]
4
  • Thank you it worked. i couldn't see that error all this time.
    – Tatenda
    Dec 25, 2015 at 20:04
  • @RahulGupta today it's just like this url('accounts/', include('accounts_app.urls')) isn't it? Sep 5, 2018 at 20:24
  • You forgot the r^ before accounts/. Sep 6, 2018 at 5:47
  • @RahulGupta no i mean when i enter path(r'^admin/', admin.site.urls) for example. I get 404 page not found requesting thishttp://127.0.0.1:8000/admin in the newest django version. But this works path('admin/', admin.site.urls) Sep 6, 2018 at 7:37
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")
]
1
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

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.

3
  • This is not a solution, but a tricky workaround. I don't think that solving circular import by changing the imported function (reverse and reverse_lazy are not the same) is good solution. May 18, 2021 at 11:10
  • This works for me, but I agree with you, is not the way to solve a circular import, but in my case, I didn't have any circular import, just changing that, works I was searchig by the error traceback and any of the other anwers work for me, then I realize the problem was related with the URLs, and I just change that and works, if somebody else has the same error and can solve it doing this, great! May 18, 2021 at 15:44
  • According to the docs (docs.djangoproject.com/en/dev/ref/urlresolvers/#reverse-lazy) you should use reverse lazy in specific cases such as providing the URL to a decorator or the URL for a class-based view. If that's what you were doing then this is the appropriate fix. Another example in the docs: docs.djangoproject.com/en/dev/topics/class-based-views/…
    – lxmmxl56
    Jun 16, 2021 at 2:26
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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.