简体   繁体   中英

Django tutorial maximum depth recursion

I am doing the django first app tutorial. When I try access the localhost webpage, I get a maximum depth recursion error. The check method keeps on getting returned until maximum depth. The code is as follows for 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")

The error code:

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

What can I do to remedy this? Thank you

The problem is that you are including the polls urls inside itself.

Remove url(r'^polls/', include('polls.urls')), from your polls/urls.py .

That line should be in your project's urls.py instead (by default, that's the one in the directory that contains settings.py )

You should move url(r'^admin/', admin.site.urls), to your project's urls.py as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM