Search code examples
pythondjangoexceptiondjango-templatesdjango-comments

Django 1.1 - comments - 'render_comment_form' returns TemplateSyntaxError


I want to simply render a built-in comment form in a template, using Django's builtin commenting module, but this returns a TemplateSyntaxError Exception.

I need help debugging this error, please, because after googling and using the Django API reference, I'm still not getting any farther.

Info:

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

<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[shortened]:

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[shortened]:

urlpatterns = patterns('',
    (r'', include('posts.urls')),
    (r'^comments/$', include('django.contrib.comments.urls')),
)

Solution

  • I had the same exact problem, render_comment_form template tag was triggering it.

    The issue is certainly with your URL config, you had it set the same way i did:

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

    The correct way is to remove the '$' after 'comments/':

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

    Otherwise django can't properly include all necessary urls under the path comments/...

    Hope this helps.