Django 1.11.1启动报错:Included URLconf does not have any patterns in it
Hey there, let's get this sorted out quickly! That error is pointing straight to your polls.urls file — Django can't find any valid URL patterns defined there, which is why it's throwing that message when you run python manage.py runserver.
Here's what you need to check and fix:
Verify your
polls/urls.pyhas a properurlpatternslist
Since you mentioned the file starts withfrom django...., make sure you've completed the rest of the file to define the required URL routes. For Django 1.11, yourpolls/urls.pyshould look something like this (matching the official tutorial structure):from django.conf.urls import url from . import views urlpatterns = [ # Example route for the polls homepage (maps to polls/) url(r'^$', views.index, name='index'), # Add other routes like detail, vote, results as per the tutorial # url(r'^(?P<question_id>[0-9]+)/$', views.detail, name='detail'), # url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'), # url(r'^(?P<question_id>[0-9]+)/results/$', views.results, name='results'), ]The key here is that
urlpatternsmust be a non-empty list containing at least oneurl()entry. If this list is missing, empty, or has syntax errors (like missing commas, incorrect imports), Django will think there are no patterns.Double-check
pollsis in yourINSTALLED_APPS
While this isn't the direct cause of the URL pattern error, it's a good sanity check to ensure your app is properly registered insettings.py:INSTALLED_APPS = [ 'polls', # Make sure this line exists 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ]Check for syntax errors in
polls/urls.py
Even a tiny typo (like a missing closing parenthesis or comma) can prevent Python from parsing the file correctly, which would make Django unable to detect theurlpatternslist. Go through the file carefully to fix any syntax issues.
Once you've updated polls/urls.py to include valid patterns, restart your runserver and the error should be gone!
内容的提问来源于stack exchange,提问作者Israel Gboluwaga

