Django/Python运行时错误:超过最大递归深度 [英] Django/Python Runtime Error: Maximum recursion depth exceeded

查看:72
本文介绍了Django/Python运行时错误:超过最大递归深度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将博客应用添加到我的Django项目中.当我将所有内容放在一起时,可以看到我的博客文章页面,但是blogapp/urls.py文件的某些内容使我在某处获得最大递归错误,而我很难找到它.首先,这是完整的错误消息:

I am trying to add a blog app to my Django project. When I put everything together, I can see my blog posts page, but something with the blogapp/urls.py file is causing me to get a maximum recursion error somewhere and I'm having a hard time finding it. First, here is the error message in full:

RuntimeError at /admin/
maximum recursion depth exceeded while calling a Python object
Request Method: GET
Request URL:    localhost/admin/  #I edited this due to a posting error
Django Version: 1.4
Exception Type: RuntimeError
Exception Value:    
maximum recursion depth exceeded while calling a Python object
Exception Location: /Users/User/tmp/newproject/DJANGO/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/utils/translation/trans_real.py in get_language, line 222
Python Executable:  /Users/User/tmp/newproject/DJANGO/bin/python
Python Version: 2.7.1

这是mysite/urls.py中的urlpatterns变量:

Here is the urlpatterns variable from mysite/urls.py:

urlpatterns = patterns('',
    url(r'^polls/', include('polls.urls')),
    url(r'^blogapp/', include('blogapp.urls')),
    url(r'^admin/', include(admin.site.urls)),
)

这是我的blogapp/urls.py文件:

And this is my blogapp/urls.py file:

from django.conf.urls import patterns, include, url
from django.views.generic import ListView
from blogapp.models import Post
urlpatterns = patterns('',
    url(r'^', ListView.as_view(queryset=Post.objects.all().order_by("-created")[:2],
                            template_name="/Users/User/tmp/newproject/DJANGO/mysite/templates/blogapp/blog.htm    l")),     
    url(r'^blog/', include('blogapp.urls')),
)

好吧,这是我的blogapp/models.py文件:

And, for good measure, this is my blogapp/models.py file:

from django.db import models

class Post(models.Model):
    '''represents a class instance of a blog entry'''
    title = models.CharField(max_length=100)
    created = models.DateTimeField()
    body = models.TextField()

    def __unicode__(self):
        return self.title

推荐答案

您似乎在内部包含了blogapp.urls.听起来不是个好主意.

You seem to be including blogapp.urls inside itself. Doesn't sound like a good idea.

这篇关于Django/Python运行时错误:超过最大递归深度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆