2012-12-15 61 views
5

我正在尝试将博客应用程序添加到我的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 

回答

16

你似乎里面包括本身blogapp.urls。听起来不是一个好主意。

+0

呃!这正是问题所在!非常感谢,我不知道为什么我没有听到! –

+0

我也陷入了类似的情况。那是什么选择? – Volatil3

+0

感谢@Daniel,我在Python脚本中遇到了类似的问题,这是由于导入问题(而不是正确的顺序)造成的。没有你的提示,我仍然会坚持下去。谢谢 ! – VivienG

-2

我会假设你想创建成员对象属性

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

理想情况下应该进入构造方法下

def __init__(self): 
''represents a class instance of a blog entry''' 
    title = models.CharField(max_length=100) 
    created = models.DateTimeField() 
    body = models.TextField() 
+0

对不起,我贴错标签的注释。它应该是“代表博客条目”,“类实例”不是我想要的(新错误)。 –

2

当代码一样,

logout call logout again

def logout(request): print 'under logout user ++++++++++++++' + str(request.POST) logout(request) return redirect('/home/')

+1

这是因为你的视图被称为注销,所以当你调用注销(请求)视图只是调用自己,造成无限递归。 – Kevin

0

的问题是,Django的退出方法是在你看来注销方法,我也面临这个问题。所以它自称并永不结束。

因此,您可以将您的视图注销方法重命名为“注销”或类似的东西。

另一种是进口的Django注销与其他名称,如下面并要求它在你的注销方法:从django.contrib.auth进口注销 作为core_logout

相关问题