Django教程最大深度递归

时间:2017-08-15 14:56:03

标签: python django recursion

我正在做django第一个应用教程。当我尝试访问localhost网页时,我得到最大深度递归错误。检查方法一直返回到最大深度。 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

我该怎么做才能解决这个问题? 谢谢

1 个答案:

答案 0 :(得分:5)

问题在于你将民意调查网址包括在内。

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

该行应该在项目的urls.py中(默认情况下,这是包含polls/urls.py的目录中的那一行)

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