为什么会出现RecursionError?

时间:2019-04-16 05:36:53

标签: django recursion django-urls

我希望该博客页面能够运行。我使用的是django == 1.11.2,其中包含2urls.py,并与include进行了链接,但是在运行时遇到了递归错误问题。

主要urls.py:

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^blog/', include('project1.urls')),
]

应用url.py:

from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^$', views.blogIndex, name='blogindex'),
    url(r'^detail/(?P<postid>.+)$', views.blogDetail, name='blogDetail'),
]

错误:

File "/Users/shahariarshanto/Desktop/blog/env_week2/lib/python3.7/site-packages/django/core/checks/urls.py", line 26, in check_resolver
    return check_method()
  File "/Users/shahariarshanto/Desktop/blog/env_week2/lib/python3.7/site-packages/django/urls/resolvers.py", line 255, in check
    warnings.extend(check_resolver(pattern))
  File "/Users/shahariarshanto/Desktop/blog/env_week2/lib/python3.7/site-packages/django/core/checks/urls.py", line 26, in check_resolver
    return check_method()
  File "/Users/shahariarshanto/Desktop/blog/env_week2/lib/python3.7/site-packages/django/urls/resolvers.py", line 255, in check
    warnings.extend(check_resolver(pattern))
  File "/Users/shahariarshanto/Desktop/blog/env_week2/lib/python3.7/site-packages/django/core/checks/urls.py", line 26, in check_resolver
    return check_method()
  File "/Users/shahariarshanto/Desktop/blog/env_week2/lib/python3.7/site-packages/django/urls/resolvers.py", line 170, in check
    warnings = self._check_pattern_name()
RecursionError: maximum recursion depth exceeded

views.py:

from django.shortcuts import render, get_object_or_404
from .models import BlogPost

def blogIndex(request):
    blogposts = BlogPost.objects.order_by('-pub_date')
    context = {
        'heading':'The Blog',
        'subheading':'',
        'title':'Blog',
        'copyright':'Pending',
        'blogposts':blogposts,
    }
    return render(request,'blog-home-2.html',context)

def blogDetail(request,postid):
    post = get_object_or_404(BlogPost, pk=postid)
    context = {
        'post' : post,
        'copyright':'Pending',
        }
    return render(request,'blog-post.html',context)

1 个答案:

答案 0 :(得分:0)

您将项目URL包含在其中,而不是包含应用程序URL。