我正在遵循Django文档中的教程,并尝试将视图映射到URL时收到以下错误:
raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf 'pollSite.urls' d
oes not appear to have any patterns in it. If you see valid patterns in the file th
en the issue is probably caused by a circular import
。我有一个pollSite
项目和一个poll
应用程序。
pollSite / pollSite / urls.py:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('polls/', include('polls.urls')),
]
pollSite / poll:
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
views.py:
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world")
我以为我可能输入了错误的内容,所以我回过头来,复制了文档中的代码,并将其直接粘贴到编辑器中,仍然遇到相同的错误。我不确定circular import
是什么,但是我还是第一次与virtualenv
合作,也不确定是否可能导致此问题。有什么建议吗?
教程,以防有人感兴趣:https://docs.djangoproject.com/en/2.2/intro/tutorial01/
答案 0 :(得分:1)
您的应用称为“民意调查”,而不是“民意调查”。因此,您必须使用该名称添加它:
path('polls/', include('poll.urls')),