Django 1.1 - comments - 'render_comment_form' returns a TemplateSyntaxError

I want to just create an inline comment form in the template using the Django inline comment module, but this returns a TemplateSyntaxError exception.

I need help debugging this error, please, because after searching the Internet and using the Django API link, I still get no further action.

information:

This is the template '_post.html' [abbreviated]:

<div id="post_{{ object.id }}">
<h2>
    <a href="{% url post object.id %}">{{ object.title }}</a>
    <small>{{ object.pub_date|timesince }} ago</small>
    </h2>
    {{ object.body }}
    {% load comments %}
    {% get_comment_count for object as comment_count %}
    <p>{{ comment_count }}</p>
    <!-- Returns 0, because no comments available  -->
    {% render_comment_form for object %}
    <!-- Returns TemplateSyntaxError -->

This is the Exception output when rendering:

Caught an exception while rendering: Reverse for 'django.contrib.comments.views.comments.post_comment'
with arguments '()' and keyword arguments '{}' not found.1  
{% load comments i18n %}
        <form action="{% comment_form_target %}" method="post">
          {% if next %}<input type="hidden" name="next" value="{{ next }}" />{% endif %}
          {% for field in form %}
            {% if field.is_hidden %}
              {{ field }}
            {% else %}
          {% if field.errors %}{{ field.errors }}{% endif %}
          <p
            {% if field.errors %} class="error"{% endif %}
            {% ifequal field.name "honeypot" %} style="display:none;"{% endifequal %}>
            {{ field.label_tag }} {{ field }}

/posts/urls.py [shorten]:

queryset = {'queryset': Post.objects.all(),
            'extra_context' : {"tags" : get_tags}
           }   
urlpatterns = patterns('django.views.generic.list_detail',
    url('^$',                           'object_list',      queryset,
        name='posts'),
    url('^blog/(?P<object_id>\d+)/$',   'object_detail',    queryset,
        name='post'),
)

/urls.py [shorten]:

urlpatterns = patterns('',
    (r'', include('posts.urls')),
    (r'^comments/$', include('django.contrib.comments.urls')),
)
+3
source share
4 answers

, render_comment_form .

, , URL-, , :

(r'^comments/$', include('django.contrib.comments.urls'))

- "$" "/":

(r'^comments/', include('django.contrib.comments.urls'))

django URL- /...

, .

+6

, URL :


   django.contrib.comments.views.comments.post_comment

, - URL-. , , , .

, urls urls.py, URL- django ?

+1

. urls.py, .

http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse

URL- , , () URLconf . . , reverse(), , , .

, , URLconf . , , , .

+1

, django.contrib.comments.views.comments.post_comment

args() kwargs {}.

The object.id value is not passed to the URL.

Take out the url tag and see if the identifier reflects the <div id="post_{{object.id}}">correct object.id

+1
source

Source: https://habr.com/ru/post/1725236/


All Articles