PacktPublishing/Django-2-by-Example

Chapter 02: Adding comments

travismoulton opened this issue · 4 comments

Has anyone else had any issues when adding the comments feature? I have all the code in, and via a get request my form renders properly to add a comment. However, when I fill in the comment fields, and hit the submit button, my template won't render. The slug isn't being passed to the url. The year, month, and date are. Did anyone else experience this? I'm completely stuck. There aren't any typos in my code because I copy and pasted it out of github into my file.

Have you solved the problem?
I change the action="." to action="", and it works.

<form action="" method="post">
    {{ comment_form.as_p }}
        {% csrf_token %}
    <p>
            <input type="submit" value="Add comment">
    </p>
</form>

Has anyone else had any issues when adding the comments feature? I have all the code in, and via a get request my form renders properly to add a comment. However, when I fill in the comment fields, and hit the submit button, my template won't render. The slug isn't being passed to the url. The year, month, and date are. Did anyone else experience this? I'm completely stuck. There aren't any typos in my code because I copy and pasted it out of github into my file.

Doesn't work for me either. Tried the form action="" that doesn’t fix the issues. The error says CommentForm' object has no attribute 'save'. Did you get any fix?

Has anyone else had any issues when adding the comments feature? I have all the code in, and via a get request my form renders properly to add a comment. However, when I fill in the comment fields, and hit the submit button, my template won't render. The slug isn't being passed to the url. The year, month, and date are. Did anyone else experience this? I'm completely stuck. There aren't any typos in my code because I copy and pasted it out of github into my file.

Doesn't work for me either. Tried the form action="" that doesn’t fix the issues. The error says CommentForm' object has no attribute 'save'. Did you get any fix?

Does your CommentForm inherit from ModelForm?

class CommentForm(forms.ModelForm):
    class Meta:
        model = Comment
        fields = ('name', 'email', 'body')

Has anyone else had any issues when adding the comments feature? I have all the code in, and via a get request my form renders properly to add a comment. However, when I fill in the comment fields, and hit the submit button, my template won't render. The slug isn't being passed to the url. The year, month, and date are. Did anyone else experience this? I'm completely stuck. There aren't any typos in my code because I copy and pasted it out of github into my file.

Doesn't work for me either. Tried the form action="" that doesn’t fix the issues. The error says CommentForm' object has no attribute 'save'. Did you get any fix?

Does your CommentForm inherit from ModelForm?

class CommentForm(forms.ModelForm):
    class Meta:
        model = Comment
        fields = ('name', 'email', 'body')

Thank you, I just debugged the same. I had typed forms.Form in place of ModelForm . Good coincidence! Now works fine!!