Django-Fluent-Comments - /rohit/post/new/ 处的 NoReverseMatch

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

我尝试了所有方法,但我不知道如何消除此错误。 需要帮助的人。 我正在使用 django-fluent-comments 进行评论,当我把这条线放在

{% render_comment_form for object %}

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

NoReverseMatch at /rohit/post/new/

Reverse for 'comments-post-comment' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['(?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/$']

i have used this for comment url:

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

My Template:

<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>

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

django-fluent-comments尝试渲染时 {% render_comment_form for object %} 它将使用反向 url 标记,但未向其传递 usernameslug 对象。

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

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

或删除 usernameslug 对象。

如果你真的想添加它们,那么你可以覆盖 django-fluent-comments 中的模板,这样每个使用 url 名称的 url 标签都会传递一个 usernameslug 个对象。

查看 Django Urls 部分了解更多信息。