我可以在其他页面上使用Django评论吗?

时间:2012-03-30 13:08:58

标签: django django-comments

我想知道是否可以将Django内置评论框架用于其他页面,这与“博客条目”无关。例如,我想在每个关于电影的页面上添加注释字段。

我尝试按照https://docs.djangoproject.com/en/dev/ref/contrib/comments/中的说明操作,但出现以下错误。我已经添加了必要的APP,并且做了syncdb。

Environment:


Request Method: GET
Request URL: http://localhost:8000/movie/603/

Django Version: 1.4
Python Version: 2.7.2
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'forms',
 'social_auth')
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 C:\xampp\htdocs\tddd27_project\templates\movie_info.html, error at line 3
   'comments' is not a valid tag library: Template library comments not found, tried django.templatetags.comments,django.contrib.staticfiles.templatetags.comments,django.contrib.admin.templatetags.comments,forms.templatetags.comments
   1 : {% extends "base.html" %}


   2 : {% load string_extras %}


   3 :  {% load comments %} 


   4 : {% block title %}{{ content.original_title }}{% endblock title %}


   5 : {% block content %}


   6 :  


   7 :  <h2>{{ content.original_title }} - ({{ content.release_date|year}})</h2>


   8 :  <table>


   9 :      <tr>


   10 :             <td><img src="http://cf2.imgobject.com/t/p/w185/{{ content.poster_path}}"></td>


   11 :             <td>{{ content.overview }}</td>


   12 :         </tr>


   13 : 


Traceback:
File "c:\tools\python27\lib\site-packages\django-1.4-py2.7.egg\django\core\handlers\base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "C:\xampp\htdocs\tddd27_project\views.py" in movie_view
  65.   return render_to_response('movie_info.html',{'content':content}, RequestContext(request))
File "c:\tools\python27\lib\site-packages\django-1.4-py2.7.egg\django\shortcuts\__init__.py" in render_to_response
  20.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "c:\tools\python27\lib\site-packages\django-1.4-py2.7.egg\django\template\loader.py" in render_to_string
  169.         t = get_template(template_name)
File "c:\tools\python27\lib\site-packages\django-1.4-py2.7.egg\django\template\loader.py" in get_template
  145.     template, origin = find_template(template_name)
File "c:\tools\python27\lib\site-packages\django-1.4-py2.7.egg\django\template\loader.py" in find_template
  134.             source, display_name = loader(name, dirs)
File "c:\tools\python27\lib\site-packages\django-1.4-py2.7.egg\django\template\loader.py" in __call__
  42.         return self.load_template(template_name, template_dirs)
File "c:\tools\python27\lib\site-packages\django-1.4-py2.7.egg\django\template\loader.py" in load_template
  48.             template = get_template_from_string(source, origin, template_name)
File "c:\tools\python27\lib\site-packages\django-1.4-py2.7.egg\django\template\loader.py" in get_template_from_string
  156.     return Template(source, origin, name)
File "c:\tools\python27\lib\site-packages\django-1.4-py2.7.egg\django\template\base.py" in __init__
  125.         self.nodelist = compile_string(template_string, origin)
File "c:\tools\python27\lib\site-packages\django-1.4-py2.7.egg\django\template\base.py" in compile_string
  153.     return parser.parse()
File "c:\tools\python27\lib\site-packages\django-1.4-py2.7.egg\django\template\base.py" in parse
  267.                     compiled_result = compile_func(self, token)
File "c:\tools\python27\lib\site-packages\django-1.4-py2.7.egg\django\template\loader_tags.py" in do_extends
  214.     nodelist = parser.parse()
File "c:\tools\python27\lib\site-packages\django-1.4-py2.7.egg\django\template\base.py" in parse
  267.                     compiled_result = compile_func(self, token)
File "c:\tools\python27\lib\site-packages\django-1.4-py2.7.egg\django\template\defaulttags.py" in load
  1043.                                           (taglib, e))

Exception Type: TemplateSyntaxError at /movie/603/
Exception Value: 'comments' is not a valid tag library: Template library comments not found, tried django.templatetags.comments,django.contrib.staticfiles.templatetags.comments,django.contrib.admin.templatetags.comments,forms.templatetags.comments

1 个答案:

答案 0 :(得分:5)

你能看到这里遗漏的东西吗?

Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'forms',
 'social_auth')

django.contrib.comments似乎不在该列表中......