我正在遵循 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/urls.py:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('polls/', include('polls.urls')),
]
民意调查网站/民意调查:
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/
您的应用称为"投票",而不是"投票"。因此,您必须使用该名称包含它:
path('polls/', include('poll.urls')),