Django 教程最大深度递归



我正在做 django 第一个应用程序教程。当我尝试访问本地主机网页时,出现最大深度递归错误。检查方法不断返回,直到最大深度。对于 urls.py,代码如下:

from django.contrib import admin
from django.conf.urls import include
from django.conf.urls import url
from polls import views
urlpatterns = [
url(r'^$', views.index, name ='index'),
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]

View.py:

from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello World. You're at the polls index")

错误代码:

File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/checks/urls.py", line 26, in check_resolver
return check_method()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/urls/resolvers.py", line 255, in check
warnings.extend(check_resolver(pattern))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/checks/urls.py", line 26, in check_resolver
return check_method()
RecursionError: maximum recursion depth exceeded

我能做些什么来解决这个问题? 谢谢

问题是您将民意调查网址包含在自身内部。

polls/urls.py中删除url(r'^polls/', include('polls.urls')),

该行应该位于项目的 urls.py 中(默认情况下,这是包含settings.py的目录中的那行(

您还应该url(r'^admin/', admin.site.urls),移动到项目的urls.py

最新更新