views:

348

answers:

2

I'm going through a Django book and I seem to be stuck. The code base used in the book is .96 and I'm using 1.0 for my Django install. The portion I'm stuck at is related to Django comments (django.contrib.comments). When I submit my comments I get "Comment post not allowed (400) Why: Missing content_type or object_pk field". I've found the Django documentation to be a bit lacking in this area and I'm hoping to get some help.

The comment box is displayed just fine, it's when I submit the comment that I get the above error (or security warning as it truly appears).

My call to the comment form:

{% render_comment_form for bookmarks.sharedbookmark shared_bookmark.id %}

My form.html code:

{% if user.is_authenticated %}
    <form action="/comments/post/" method="post">
     <p><label>Post a comment:</label><br />
     <textarea name="comment" rows="10" cols="60"></textarea></p>
     <input type="hidden" name="options" value="{{ options }}" />
     <input type="hidden" name="target" value="{{ target }}" />
     <input type="hidden" name="gonzo" value="{{ hash }}" />
     <input type="submit" name="post" value="submit comment" />
    </form>
{% else %}
    <p>Please <a href="/login/">log in</a> to post comments.</p>
{% endif %}

Any help would be much appreciated.

My view as requested:

def bookmark_page(request, bookmark_id):
    shared_bookmark = get_object_or_404(
     SharedBookmark,
     id=bookmark_id
    )
    variables = RequestContext(request, {
     'shared_bookmark': shared_bookmark
    })
    return render_to_response('bookmark_page.html', variables)
A: 

Django underwent a huge amount of change between 0.96 and 1.0, so it's not surprising you're having problems.

For your specific issue, see here.

However I would suggest you find a more up-to-date book. It's not just the comments, but whole areas of Django are completely different from 0.96 - in particular the admin. If it's the official 'Django book', you can find the draft of version 2 (which targets Django 1.0) here.

Daniel Roseman
I've been able to work through various other differences between the .96 and 1.0 code in the book. I've just hit a stumbling block with this one particular section. In fact, I've had to change some of the code to 1.0 to get it working up to this point. I have a feeling my issue is related to the anti-spam features and hidden fields, I'm just not sure how.
kfordham281
A: 

It's not perfect, but I've worked around this. I used the form.html included with Django itself and that got me past the "Comment post not allowed (400)" message and posted my comment successfully. It includes a few other fields but since I didn't define my own form in forms.py that's to be expected I suppose. At any rate, I seem to have worked around it. Thanks for looking at my question.

kfordham281