我正在嘗試將博客應用程序添加到我的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