19

I'm 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

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)),
)

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')),
)

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

4 Answers 4

48

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

Sign up to request clarification or add additional context in comments.

3 Comments

Ugh! That was exactly the problem! Thank you so much, I don't know why I didn't catch that!
I am into similar situation. what is alternative of that?
Thanks @Daniel, I had a similar problem in a Python script and it was due to an import problem (not the right order). Without your hint I would be still stuck with it. Thanks !
5

The problem is that django logout method is in your view logout method. So it calls itself and never ends.

So you may rename your view logout method as 'signout' or something like that.

Other way is import django logout with other name like below and called it in your logout method: from django.contrib.auth import logout as core_logout

Comments

1

I got the similar error:

RecursionError: maximum recursion depth exceeded in comparison

When creating and saving Person object in save() overridden in Person class as shown below:

from django.db import models

class Person(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)

    # ...
    
    def save(self, *args, **kwargs): # Here
        person = Person(first_name='Soi', last_name='Tato')
        person.save()

So, it seems like person.save() calls save() in Person class again and again, then finally caused the error.

Comments

-2

I would assume you're trying to create member object properties

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

Which should ideally go into The constructor method under

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

1 Comment

Sorry, I mislabeled the comment. It should be 'represents a blog entry', a 'class instance' was not what I was going for (newb mistake).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.