Django - The included urlconf doesn't have any patterns in it

前端 未结 8 2064
情话喂你
情话喂你 2020-12-05 02:16

My website, which was working before, suddenly started breaking with the error

ImproperlyConfigured at / The included urlconf resume.urls doesn\'t h

相关标签:
8条回答
  • 2020-12-05 02:20

    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.

    0 讨论(0)
  • 2020-12-05 02:21

    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'),
        ....
    )
    
    0 讨论(0)
  • 2020-12-05 02:22

    check for correct variable name in your app, if it is "

    urlpatterns

    " or any thing else. Correcting name helped me

    0 讨论(0)
  • 2020-12-05 02:22

    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

    0 讨论(0)
  • 2020-12-05 02:39

    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.

    0 讨论(0)
  • 2020-12-05 02:39

    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.

    0 讨论(0)
提交回复
热议问题