我正在尝试将博客应用程序添加到我的Django项目中。当我把所有东西放在一起时,我可以看到我的博客文章页面,但是blogapp/urls.py文件导致我在某处发生最大递归错误,而且我很难找到它。首先,这里是完全错误消息:Django/Python运行时错误:超过最大递归深度
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/antonioalaniz1/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/antonioalaniz1/tmp/newproject/DJANGO/bin/python
Python Version: 2.7.1
下面是从的mysite/urls.py变量的URL模式:
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls')),
url(r'^blogapp/', include('blogapp.urls')),
url(r'^admin/', include(admin.site.urls)),
)
这是我blogapp/urls.py文件:
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/antonioalaniz1/tmp/newproject/DJANGO/mysite/templates/blogapp/blog.htm l")),
url(r'^blog/', include('blogapp.urls')),
)
而且,良好的措施,这是我blogapp/models.py文件:
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
呃!这正是问题所在!非常感谢,我不知道为什么我没有听到! –
我也陷入了类似的情况。那是什么选择? – Volatil3
感谢@Daniel,我在Python脚本中遇到了类似的问题,这是由于导入问题(而不是正确的顺序)造成的。没有你的提示,我仍然会坚持下去。谢谢 ! – VivienG