Reputation: 3274
My website, which was working before, suddenly started breaking with the error
ImproperlyConfigured at / The included urlconf resume.urls doesn't have any patterns in it
The project base is called resume. In settings.py I have set
ROOT_URLCONF = 'resume.urls'
Here's my resume.urls, which sits in the project root directory.
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^resume/', include('resume.foo.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
(r'^accounts/login/$', 'django.contrib.auth.views.login'),
#(r'^employer/', include(students.urls)),
(r'^ajax/', include('urls.ajax')),
(r'^student/', include('students.urls')),
(r'^club/(?P<object_id>\d+)/$', 'resume.students.views.club_detail'),
(r'^company/(?P<object_id>\d+)/$', 'resume.students.views.company_detail'),
(r'^program/(?P<object_id>\d+)/$', 'resume.students.views.program_detail'),
(r'^course/(?P<object_id>\d+)/$', 'resume.students.views.course_detail'),
(r'^career/(?P<object_id>\d+)/$', 'resume.students.views.career_detail'),
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': 'C:/code/django/resume/media'}),
)
I have a folder called urls and a file ajax.py inside. (I also created a blank init.py in the same folder so that urls would be recognized.) This is ajax.py.
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^star/(?P<object_id>\d+)$', 'resume.students.ajax-calls.star'),
)
Anyone know what's wrong? This is driving me crazy.
Thanks,
Upvotes: 64
Views: 85167
Reputation: 43
In my case, i was using a class based view UpdateView
and in sucess_url
attribute i was passing
sucess_url = redirect(reverse('my url name'))
But it break the code, because for some reason behind the scenes Django already make a redirect giving a error of "urlpatterns failed or circular import".
For solve this just remove redirect function and your code will work normally
sucess_url = reverse('your url name')
Upvotes: 0
Reputation: 14255
Yet another possible cause for this type of error is the improper use of reverse()
or reverse_lazy()
.
For example, if you inadvertently confuse the signature of reverse
with that of the url
tag, and do something like this
reverse('my_view_name', 123)
then you'll see
The included URLconf '123' does not appear to have any patterns in it.
That should be something like
reverse('my_view_name', args=[123])
Upvotes: 0
Reputation: 1
django.urls.reverse() to django.urls.reverse_lazy() This will instantly solve it.
Upvotes: 0
Reputation: 1
In my case using comma at the end of path in App's urls.py solved the issue.
example:-
urlpatterns =[
path('', views.index, name='app')**,**
]
stars in the code are for highlighting the comma only.
Upvotes: 0
Reputation: 137
django.urls.reverse()
-->django.urls.reverse_lazy()
This will instantly solve it.
Upvotes: 1
Reputation: 177
Check the name of the variable.
The cause of my error was using "urlspatterns"
in lieu of "urlpatterns"
.
Correcting the name of the variable solved the issue for me.
Upvotes: 4
Reputation: 21
In my case, it was because of tuple unpacking. I only had one url and the root cause for this ImproperlyConfigured
error was
TypeError: 'URLPattern' object is not iterable
I used a trailing comma at the end and it resolved the issue.
urlpatterns = (url(...) , )
Upvotes: 2
Reputation: 1
Check the imported modules in views.py if there is any uninstalled modules you found remove the module from your views.py file. It's Fix for me
Upvotes: 0
Reputation: 598
check for correct variable name in your app, if it is "
urlpatterns
" or any thing else. Correcting name helped me
Upvotes: 15
Reputation: 645
Note: For some reason, for me this error also went away after I saved another file. So the first time the error appeared, I had saved a file in which I specified the wrong widget in the forms.py
file:
extra_field = forms.CharField(widget=forms.TextField())
instead of
extra_field = forms.CharField(widget=forms.TextInput())
After changing it to the correct version (TextInput) and saving the forms.py file, the error was still showing in my console. After saving another file (e.g. models.py) the error disappeared.
Upvotes: 0
Reputation: 1821
In my case I had the following error:
ImproperlyConfigured: The included URLconf 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 url patterns were valid, but the problem was an Import error caused by a typo. I typed restframework
instead of rest_framework
.
Upvotes: 0
Reputation: 3452
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.
Upvotes: 101
Reputation: 36290
I got this error when trying to reverse (and reverse_lazy) using RedirectView and parameters from the url. The offending code looked like this:
from django.views.generic import RedirectView
from django.core.urlresolvers import reverse
url(r'^(?P<location_id>\d+)/$', RedirectView.as_view(url=reverse('dailyreport_location', args=['%(location_id)s', ]))),
The fix is to use this url in urlpatterns:
from django.views.generic import RedirectView
url(r'^(?P<location_id>\d+)/$', RedirectView.as_view(url='/statistics/dailyreport/%(location_id)s/')),
ANSWER: The fix so you can still use the name of the url pattern:
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
urlpatterns = patterns('',
....
url(r'^(?P<location_id>\d+)/$', lambda x, location_id: HttpResponseRedirect(reverse('dailyreport_location', args=[location_id])), name='location_stats_redirect'),
....
)
Upvotes: 1
Reputation: 11883
IN my case I got this error during deployment. Apache kept giving me the "AH01630: client denied by server configuration" error. This indicated that was wrong with apache configuration. To help troubleshoot I had turned on Debug=True in settings.py when I saw this error.
In the end I had to add a new directive to the static files configuration inside apache config. When the static files were not accessible and Debug in django settings was set to true this error was getting triggered somehow.
Upvotes: 2
Reputation: 1321
Check your patterns for include statements that point to non-existent modules or modules that do not have a urlpatterns
member. I see that you have an include('urls.ajax')
which may not be correct. Should it be ajax.urls
?
Upvotes: 34