views:

419

answers:

3

Hello,

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')),
)
+1  A: 

The error message is indicated that it can't find a reverse url for:


   django.contrib.comments.views.comments.post_comment

So basically something isn't configured right in your urls. Without being able to see more of how things are setup it's difficult to know exactly what.

Maybe try re-ordering the urls pattern includes in your urls.py, to force the django comments urls to the top?

John Montgomery
+1  A: 

I had this same problem today. I was referencing a view in urls.py that I hadn't created yet.

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

As part of working out which URL names map to which patterns, the reverse() function has to import all of your URLconf files and examine the name of each view. This involves importing each view function. If there are any errors whilst importing any of your view functions, it will cause reverse() to raise an error, even if that view function is not the one you are trying to reverse.

Make sure that any views you reference in your URLconf files exist and can be imported correctly. Do not include lines that reference views you haven't written yet, because those views will not be importable.

Matt McCormick
+1  A: 

This error is saying that it found the view django.contrib.comments.views.comments.post_comment

but no args () or kwargs{} were passed.

Its not passing a value for object.id into the url.

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

czarchaic