Reputation: 372
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('polls/', include('polls.urls')),
]
There is an error when i add url to url.py.
when i run the code in terminal : 'python manage.py runserver' ; then the follwing error is displayed in the terminal -
django.core.exceptions.ImproperlyConfigured: The included URLconf
'<module 'polls.urls' from
'C:\\Users\\Administrator\\PycharmProjects\\website2\\mysite\\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.
I searched everywhere for the solution but i couldn't find it. Please help me to get out of it.
Upvotes: 5
Views: 10698
Reputation: 1
make sure the urls lists variable name is urlpatterns in your app django specifically checks for that name ,if name mismatches it throws that circular import error
Upvotes: 0
Reputation: 1214
I think this error most of u misunderstand, circular error imports are very rare in django only in flask it is frequent .
This error is caused by mispelling 'urlpatterns' in the urls.py which has been created in a django app.
Also it can be caused by not defining it in your urlpatterns in the urls.py file
Probably the error is caused by one of the above.
Its that easy
Upvotes: 7
Reputation: 372
This error might be coming because of the adimn in urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('polls/', include('polls.urls')),
]
When the polls path was removed by me, the website was running properly. So try comment the polls path in urls
urlpatterns = [
path('admin/', admin.site.urls),
#path('polls/', include('polls.urls')),
]
Upvotes: 3
Reputation: 16052
make sure in your polls
app, you have a file called urls.py
, which should look something like this:
from django.urls import path
from . import views
urlpatterns = [
path('', views.your_view),
]
If you haven't configured the views.py
page in your polls
app, then you can leave urlpatterns blank for now and you shouldn't see any errors.
Upvotes: 2