Django-Fluent-Comments - NoReverseMatch at / rohit / post / new /

时间:2017-04-11 18:47:04

标签: python django django-urls django-comments

我尝试了所有的东西,但我不知道如何删除此错误。 需要帮助的人。 我正在使用django-fluent-comments评论和当我把这行

  

{%render_comment_form for object%}

获取评论表格。我收到了这个错误:

   / rohit / post / new /

的NoReverseMatch      

使用参数'()'和关键字参数'{}'找不到'comments-post-comment'的反转。 1种模式   试过:['(?P \ w +)/ post /(?P [\ w - ] +)/ comments / post / $']

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/rohit/post/new/

Django Version: 1.10.2
Python Version: 3.4.4
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'pagination',
 'postman',
 'pinax.notifications',
 'fluent_comments',
 'crispy_forms',
 'django_comments',
 'mailer',
 'student',
 'teacher',
 'classroom',
 'bootstrapform',
 'posts',
 'background']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'pagination.middleware.PaginationMiddleware']


Template error:
In template C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\fluent_comments\templates\comments\form.html, error at line 7
   Reverse for 'comments-post-comment' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['(?P<username>\\w+)/post/(?P<slug>[\\w-]+)/comments/post/$']   1 : {% load comments i18n crispy_forms_tags fluent_comments_tags %}
   2 : 
   3 : {% if not form.target_object|comments_are_open %}
   4 :     <p>{% trans "Comments are closed." %}</p>
   5 : {% else %}
   6 :   {% if not form.helper or not form.helper.form_tag %}
   7 :     <form id="comment-form-{{ form.target_object.pk }}" data-object-id="{{ form.target_object.pk }}" action=" {% comment_form_target %} " method="post" class="{% block form_class %}{{ form.helper.form_class|default:'js-comments-form comments-form form-horizontal' }}{% endblock %}"
   8 :           data-ajax-action="{% url 'comments-post-comment-ajax' %}">
   9 :       {% if next %}<div><input type="hidden" name="next" value="{{ next }}" /></div>{% endif %}
   10 :   {% endif %}
   11 : 
   12 :       {% block comment_form %}
   13 :         {% block form_fields %}
   14 :           {% crispy form %}
   15 :         {% endblock %}
   16 : 
   17 :         {% block form_actions %}


Traceback:

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\core\handlers\exception.py" in inner
  39.             response = get_response(request)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\core\handlers\base.py" in _legacy_get_response
  249.             response = self._get_response(request)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\core\handlers\base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\core\handlers\base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view
  23.                 return view_func(request, *args, **kwargs)

File "C:\Users\rohit\Desktop\GBPEC\portal\GBPEC_PORTAL\classroom\views.py" in post_full
  230.  return render(request, "post_detail.html", context)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\shortcuts.py" in render
  30.     content = loader.render_to_string(template_name, context, request, using=using)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\loader.py" in render_to_string
  68.     return template.render(context, request)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\backends\django.py" in render
  66.             return self.template.render(context)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\base.py" in render
  208.                     return self._render(context)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\base.py" in _render
  199.         return self.nodelist.render(context)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django_comments\templatetags\comments.py" in render
  191.             formstr = render_to_string(template_search_list, context_dict)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\loader.py" in render_to_string
  68.     return template.render(context, request)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\backends\django.py" in render
  66.             return self.template.render(context)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\base.py" in render
  208.                     return self._render(context)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\base.py" in _render
  199.         return self.nodelist.render(context)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\defaulttags.py" in render
  315.                 return nodelist.render(context)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\defaulttags.py" in render
  315.                 return nodelist.render(context)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\template\library.py" in render
  203.         output = self.func(*resolved_args, **resolved_kwargs)

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django_comments\templatetags\comments.py" in comment_form_target
  339.     return django_comments.get_form_target()

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django_comments\__init__.py" in get_form_target
  74.         return reverse("comments-post-comment")

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\urls\base.py" in reverse
  91.     return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))

File "C:\Users\rohit\Desktop\GBPEC\portal\lib\site-packages\django\urls\resolvers.py" in _reverse_with_prefix
  392.             (lookup_view_s, args, kwargs, len(patterns), patterns)

Exception Type: NoReverseMatch at /rohit/post/new/
Exception Value: Reverse for 'comments-post-comment' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['(?P<username>\\w+)/post/(?P<slug>[\\w-]+)/comments/post/$']
  

我用它来评论网址:

url(r'^(?P<username>\w+)/post/(?P<slug>[\w-]+)/comments/', include('fluent_comments.urls')),
  

我的模板:

<div class="mdl-card__title" style="margin: 0 auto;">
                          <h2 class="mdl-card__title-text">{{ post.title }}</h2>
                        </div>
                        <div class="mdl-card__supporting-text" style="margin:0 auto;">
                         <p> Content : {{ post.content|linebreaksbr }}</p>
                         <p>
                         {% if file %}
                         Files : 
                         {% for f in file %}
                         <a href="{{ f.file.url }}">{{ f.filename }}</a>
             <br>
                         {% endfor %}
                        {% endif %}
                         </p>
                         <p>
                        {{ post.post_type }}
                        </p>
                        {{ post.timestamp|timesince }} ago by {{ post.user }}
                        </div>
             {% if author %}
                        <div class="mdl-card__actions mdl-card--border">
                          <a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect mdl-button--colored" data-upgraded=",MaterialButton,MaterialRipple"  href="/{{ request.user.username }}/post/{{ post.slug }}/edit/">Edit Post</a>
                          <a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect mdl-button--accent" data-upgraded=",MaterialButton,MaterialRipple"  href="/{{ request.user.username }}/post/{{ post.slug }}/delete/">Delete Post</a>
                        </div>
              {% endif %}

                    </div>
          {% render_comment_list for object %}
          {% render_comment_form for object %}
                </div>

            </div>
        </div>

1 个答案:

答案 0 :(得分:2)

由于您指定的网址而发生错误。您fluent_comments.urls中包含的^(?P<username>\w+)/post/(?P<slug>[\w-]+)/comments/中的任何已命名网址都需要传递usernameslug个对象。

django-fluent-comments尝试渲染时 {% render_comment_form for object %}它会使用反向网址标记,但它没有传递usernameslug个对象。

相反,您可以执行django-fluent-comments作者suggested的操作,并将以下内容添加到url.py

urlpatterns += patterns('',
    url(r'^blog/comments/', include('fluent_comments.urls')),
)

或删除usernameslug个对象。

如果您确实要添加它们,则可以覆盖django-fluent-comments中的模板,以便使用网址名称的每个url标记都会传递username和{{1}对象。

有关详细信息,请查看Django Urls部分。