0

I'm getting a strange error message with [django-ratings][1]. The following is in my urls.py:

url(r'^rate/(?P<object_id>\d+)/(?P<score>\d+)/', AddRatingFromModel(),{
    'app_label': 'spiceapp',
    'model': 'spice',
    'field_name': 'rating',
}),

If I navigate to this page: /spiceapp/rate/1/2, I get the following error:

Caught AttributeError while rendering: 'AddRatingFromModel' object has no attribute 'name'

What would cause this to happen?

Environment:


Request Method: GET
Request URL: http://localhost:8000/spiceapp/rate/1/2/

Django Version: 1.3.1
Python Version: 2.7.2
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.humanize',
 'django.contrib.markup',
 'mptt',
 'treenav',
 'djangoratings',
 'django.contrib.databrowse',
 'pinax.templatetags',
 'django_facebook',
 'aiteo',
 'haystack',
 'notification',
 'staticfiles',
 'debug_toolbar',
 'mailer',
 'uni_form',
 'crispy_forms',
 'django_openid',
 'ajax_validation',
 'timezones',
 'emailconfirmation',
 'announcements',
 'pagination',
 'friends',
 'messages',
 'oembed',
 'groups',
 'threadedcomments',
 'wakawaka',
 'swaps',
 'tagging',
 'bookmarks',
 'photologue',
 'avatar',
 'flag',
 'microblogging',
 'locations',
 'django_sorting',
 'tagging_ext',
 'smuggler',
 'voting',
 'pinax.apps.signup_codes',
 'pinax.apps.analytics',
 'pinax.apps.blog',
 'pinax.apps.tribes',
 'pinax.apps.photos',
 'pinax.apps.topics',
 'pinax.apps.threadedcomments_extras',
 'about',
 'account',
 'waitinglist',
 'spiceapp',
 'bbauth',
 'profiles']
Installed Middleware:
['django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django_openid.consumer.SessionConsumer',
 'django.contrib.messages.middleware.MessageMiddleware',
 'groups.middleware.GroupAwareMiddleware',
 'pinax.apps.account.middleware.AuthenticatedMiddleware',
 'pinax.apps.account.middleware.LocaleMiddleware',
 'django.middleware.doc.XViewMiddleware',
 'pagination.middleware.PaginationMiddleware',
 'django_sorting.middleware.SortingMiddleware',
 'pinax.middleware.security.HideSensistiveFieldsMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware']


Template error:
In template /Users/nb/Desktop/myenv2/lib/python2.7/site-packages/debug_toolbar/templates/debug_toolbar/base.html, error at line 48
   Caught AttributeError while rendering: 'AddRatingFromModel' object has no attribute '__name__'
   38 :     </div>


   39 :     {% for panel in panels %}


   40 :         {% if panel.has_content %}


   41 :             <div id="{{ panel.dom_id }}" class="panelContent">


   42 :                 <div class="djDebugPanelTitle">


   43 :                     <a href="" class="djDebugClose">{% trans "Close" %}</a>


   44 :                     <h3>{{ panel.title|safe }}</h3>


   45 :                 </div>


   46 :                 <div class="djDebugPanelContent">


   47 :                     <div class="scroll">


   48 :                          {{ panel.content|safe }} 


   49 :                     </div>


   50 :                 </div>


   51 :             </div>


   52 :         {% endif %}


   53 :     {% endfor %}


   54 :     <div id="djDebugWindow" class="panelContent"></div>


   55 : </div>


   56 : 

Traceback:
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  178.                 response = middleware_method(request, response)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/debug_toolbar/middleware.py" in process_response
  104.                     smart_unicode(self.debug_toolbars[request].render_toolbar() + self.tag))
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/debug_toolbar/toolbar/loader.py" in render_toolbar
  78.         return render_to_string('debug_toolbar/base.html', context)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
  183.         return t.render(Context(dictionary))
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/test/utils.py" in instrumented_test_render
  60.     return self.nodelist.render(context)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/base.py" in render
  744.                 bits.append(self.render_node(node, context))
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/debug.py" in render_node
  73.             result = node.render(context)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/defaulttags.py" in render
  227.                 nodelist.append(node.render(context))
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/defaulttags.py" in render
  311.             return self.nodelist_true.render(context)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/base.py" in render
  744.                 bits.append(self.render_node(node, context))
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/debug.py" in render_node
  73.             result = node.render(context)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/debug.py" in render
  90.             output = self.filter_expression.resolve(context)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/base.py" in resolve
  510.                 obj = self.var.resolve(context)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/base.py" in resolve
  653.             value = self._resolve_lookup(context)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/base.py" in _resolve_lookup
  698.                             current = current()
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/debug_toolbar/panels/request_vars.py" in content
  35.             'view_func': '%s.%s' % (self.view_func.__module__, self.view_func.__name__),

Exception Type: TemplateSyntaxError at /spiceapp/rate/1/2/
Exception Value: Caught AttributeError while rendering: 'AddRatingFromModel' object has no attribute '__name__'
user1328021
  • 9,110
  • 14
  • 47
  • 78

1 Answers1

1

This looks like an old bug in django-debug-toolbar. Do you happen to know which version you are using? Because the file looks like the one in this commit. Several fixes has been made to that file since then: this one, for example seems to address specifically your issue.

In any case, the version you're using seems to predate the 2nd of June, 2011. I would try looking into updating your environment.

jro
  • 9,300
  • 2
  • 32
  • 37
  • Thanks yes I'm using Django 1.2.1 ... I know it's old, but I'm worried if I update it will break more stuff. – user1328021 Oct 30 '12 at 15:31
  • Well, from your stack trace it seems like you have the sources available. You might want to try patching the file yourself, using the code posted in the last link in my answer. [Over here](https://github.com/django-debug-toolbar/django-debug-toolbar/commits/master/debug_toolbar/panels/request_vars.py) you can find the commit history of that file: work upwards from that commit, and see when your problem is solved. – jro Oct 30 '12 at 15:36
  • Update- I updated that file and things are working great now. Thanks so much. Really appreciate your suggestion :-) Eventually I will have to update.. once I'm feeling more brave. – user1328021 Oct 30 '12 at 15:51