0

我收到一条关于 [django-ratings][1] 的奇怪错误消息。以下在我的 urls.py 中:

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

如果我导航到此页面:/spiceapp/rate/1/2,我会收到以下错误:

渲染时捕获 AttributeError:“AddRatingFromModel”对象没有属性“名称

什么会导致这种情况发生?

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__'
4

1 回答 1

1

这看起来像是django-debug-toolbar中的一个老错误。您碰巧知道您使用的是哪个版本吗?因为该文件看起来像这个提交中的那个。从那时起,对该文件进行了一些修复:例如,这个似乎专门解决了您的问题。

无论如何,您使用的版本似乎早于 2011 年 6 月 2 日。我会尝试更新您的环境。

于 2012-10-30T15:30:09.803 回答