Django教程:最大深度递归

5
我正在进行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

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


请包含来自投票模块的urls.py。无论您访问哪个视图,请附带完整的错误回溯信息。 - Arpit Solanki
1个回答

9
问题在于您在自己的URL中包含了投票URL。
请从您的polls/urls.py中删除url(r'^polls/', include('polls.urls'))
那一行应该放在您项目的urls.py中(默认情况下,这是包含settings.py文件的目录中的文件)。
您还应该将url(r'^admin/', admin.site.urls)移动到您项目的urls.py中。

1
在我的情况下,我试图导入一个与我的项目和主应用程序同名的模块,导致URL冲突。我本可以更改URL路径或重命名项目(我选择了后者以确保安全)。 - Eric Darchis

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接