使用django_model_comments的WSGIRequest错误

时间:2013-02-03 22:22:21

标签: django django-templates django-comments

很抱歉发布与错误相关的其他问题:

  

'WSGIRequest'对象没有属性'find'

但我真的无法在任何地方找到答案。

我正在尝试使用django_model_comments应用,它扩展了django的评论应用。 页面告诉了所有内容,但是在运行服务器时,我得到以下内容:

Environment:

Request Method: GET
Request URL: http://localhost:8000/feed/1

Django Version: 1.4.3
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.staticfiles',
 'model_comments',
 'django.contrib.comments',
 'pinax_theme_bootstrap_account',
 'pinax_theme_bootstrap',
 'django_forms_bootstrap',
 'account',
 'metron',
 'user_app',
 'feed_app']
Installed Middleware:
['django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware']

Template error:
In template D:\Docs\Work\repo\project\feed_app\templates\feed.html, error at line 10
   'WSGIRequest' object has no attribute 'find'
  1 : {% load model_comment_tags %}
  2 : {% get_comment_form for feed as post_form %}             
  3 : {% render_comment_form post_form %}

Traceback:
File "D:\Docs\Work\repo\so_virtual_env\lib\site-packages\django\core\handlers\base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "D:\Docs\Work\repo\project\feed_app\views.py" in get_user_feed
  37.                     'feed': private_feed})
File "D:\Docs\Work\repo\so_virtual_env\lib\site-packages\django\template\base.py" in render
  140.             return self._render(context)
File "D:\Docs\Work\repo\so_virtual_env\lib\site-packages\django\template\base.py" in _render
  134.         return self.nodelist.render(context)
File "D:\Docs\Work\repo\so_virtual_env\lib\site-packages\django\template\base.py" in render
  823.                 bit = self.render_node(node, context)
File "D:\Docs\Work\repo\so_virtual_env\lib\site-packages\django\template\debug.py" in render_node
  74.             return node.render(context)
File "D:\Docs\Work\repo\so_virtual_env\lib\site-packages\django\template\defaulttags.py" in render
  281.                 return nodelist.render(context)
File "D:\Docs\Work\repo\so_virtual_env\lib\site-packages\django\template\base.py" in render
  823.                 bit = self.render_node(node, context)
File "D:\Docs\Work\repo\so_virtual_env\lib\site-packages\django\template\debug.py" in render_node
  74.             return node.render(context)
File "D:\Docs\Work\repo\project\model_comments\templatetags\model_comment_tags.py" in render
  26.         return self.func(context)
File "D:\Docs\Work\repo\project\model_comments\templatetags\model_comment_tags.py" in wrap
  75.         form.set_request(request)
File "D:\Docs\Work\repo\project\model_comments\forms.py" in set_request
  106.             self.fields['from_url'].initial = unicode(Url(request))
File "D:\Docs\Work\repo\project\model_comments\url_util.py" in __init__
  11.         self.scheme, self.netloc, self.path, self.params, self.query_string, self.fragment = urlparse.urlparse(url)
File "C:\Python27\Lib\urlparse.py" in urlparse
  134.     tuple = urlsplit(url, scheme, allow_fragments)
File "C:\Python27\Lib\urlparse.py" in urlsplit
  173.     i = url.find(':')

Exception Type: AttributeError at /feed/1
Exception Value: 'WSGIRequest' object has no attribute 'find'

使用templatetag时会发生错误:

html = "{% load model_comment_tags %} \
        {% get_comment_form for feed as post_form %}\
        {% render_comment_form post_form %}"
t = template.Template(html)
html = t.render(RequestContext(request, {'feed': private_feed}))

我已经检查了所有中间件,应用程序的顺序,删除了.pyc文件,并在模板中进行了各种实验。

1 个答案:

答案 0 :(得分:2)

django_model_comments库中存在一个错误,因为here它们传递了HttpRequest对象,而不是Url类here所期望的字符串,所以它应该调用{{1}请求对象上的方法,然后将字符串传递给Url类。

所以基本上替换

build_absolute_uri()

unicode(Url(request))