danirus / django-comments-xtd

A pluggable Django comments application with thread support, follow-up notifications, mail confirmation, like/dislike flags, moderation, a ReactJS plugin and Bootstrap 5.3.
https://django-comments-xtd.readthedocs.io
BSD 2-Clause "Simplified" License
594 stars 158 forks source link

Comments do not post: raises page not found error #239

Closed dtdibaba closed 3 years ago

dtdibaba commented 3 years ago

When I try to post comment or preview, it raises Page not found error. It shows this URL http://127.0.0.1:8000/comments/post/.

I installed both django_comments and django_comments_xtd Added 'django_comments_xtd', 'django_comments', to INSTALLED_APPS

I included path('comments/, include(django.comments_xtd.urls)) in my project and app urls

Added the CommentModerator class to my model. And added

{% load comments %} {% load comments_xtd %}

....

{% if new_comment %} {% else %}

Leave a comment

{{ comment_form.as_p }} {% csrf_token %}
{% endif %}

{% if comment_count %}


{% render_comment_list for post %}

{% endif %}

{% get_comment_count for post as comment_count %} <div class="py-4 text-center> Back to the post list  ⋅  {{ comment_count }} comment{{ comment_count|pluralize }} ha{{ comment_count|pluralize:"s,ve"}} been posted.

{% if post.allow_comments %}

Your comment

{% render_comment_form for post %}

{% endif %}

{% if comment_count %}

{% endif %}

before the {% endblock % tags in my detail.html template

I checked in my project lib/python3.8/site-packages/ folder and did not see django_comments_xtd folder. So, I cloned it from Git but it did not work.

I followed this tutorial: https://django-comments-xtd.readthedocs.io/en/latest/tutorial.html Am I supposed to copy the django_comments templates to my project templates? Can any one help?

danirus commented 3 years ago

It sounds as if you forgot to activate the virtualenv before installing django-comments-xtd. As you already pointed out, a directory called django_comments_xtd has to exist in lib/python3.8/site-packages/. Try to activate the virtualenv and then install the package, in that order, as stated in the introduction of the tutorial.

dtdibaba commented 3 years ago

Here are my codes: source ~/Desktop/WEB2/bin/activate pip3 install django-comments-xtd

Feedback: Requirement already satisfied: django-comments-xtd in ./Desktop/WEB2/lib/python3.8/site-packages/django-comments-xtd (2.8.1)

I have added: 'django_comments', 'django_comments_xtd', to my INSTALLED_APPS.

And I have added: COMMENTS_APP = "django_comments_xtd"

Screen Shot 2020-11-21 at 10 36 54

The error message says:

Request Method: POST

http://127.0.0.1:8000/comments/post/ django.contrib.flatpages.views.flatpage

No flatpage matches the query.

danirus commented 3 years ago

As the error says, you don't have a flatpage matching the query. What makes you think it's an issue with django-comments-xtd?

dtdibaba commented 3 years ago

In the demo, I have not seen a flatepage created for the comments objects. Should I save the templates from the django_comments_xtd in a flatepage folder under my app's template directory? In my app, I have a Comment model that shows comments and counts the number of comments for a post. That is too basic. It does not have a moderator functionality. All comments are free and the comments appear on the post even though I can disable or delete a comment from the admin page. It is a bare minimum one. What I am trying to do is to improve the comment system such that all comments are moderated before they appear on the post except those posted by authenticated users.

I have a FlatePage on my admin site, do I have to create it from the admin page? I get the basic comments on my admin dashboard because I have created a model and registered it. In the django_comments_xtd, case I thought the package itself handles that I have not created a Comment model for it or link with the existing one. The only model I created for the django_comment_xtd is the PostCommentModerator model. When I run the server, it shows me: " ?: (2_0.W001) Your URL pattern '^comments/' has a route that contains '(?P<', begins with a '^', or ends with a '$'. This was likely an oversight when migrating to django.urls.path(). ?: (2_0.W001) Your URL pattern '^comments/' has a route that contains '(?P<', begins with a '^', or ends with a '$'. This was likely an oversight when migrating to django.urls.path(). " The only place where url or re_path and (?P<', or $ is used is in the django_comments and django_comments_xtd packages. Do you think this is the reason? It seems django_comments_xtd does not render the preview.html and other templates. Nor does it save the comments to the database. What should I do to get both? The error is related to that. When I fill out comments to the form rendered by my detail.html template after adding the render_comment_form and render_xtdcomment_tree tags , and hit post or preview, it raises the error as above. I hope this helps to understand how they are linked.

danirus commented 3 years ago

django-comments-xtd doesn't have a requirement on the flatpages app. Here I would be glad to help you if there was a problem with django-comments-xtd. But that is not the case. To understand how to integrate the app with Django projects you could try to get acquainted with the code of the tutorial, and additionally and very valuable, playing with the demos. Good luck.

dtdibaba commented 3 years ago

I understand, it is not the problem of django-comments-xtd. I assume I might have missed something. The issue is it does not take me to the preview page or post the comment at all. So, the problem is, the django-comment-xtd forms, models, and views are not properly working for me. It does not save the comments on the admin page under COMMENTS XTD either.
Sorry for bothering you,and thanks.

danirus commented 3 years ago

It looks like you forgot to create the template for a flatpage. The flatpages app is documented here.

I recommend you to slow down and enjoy learning Python/Django. Django is a large product that will save you a lot of time, code and headaches, it takes time to master it. I still don't. I find myself reading the docs very often, and I started using it before v1.0.

As for django-comments-xtd, I added 3 demo projects (in addition to the tutorial) that you can run to understand how to use it. It is in the docs, here.

danirus commented 3 years ago

Don't hesitate to reopen the issue if you find out there is issue in django-comments-xtd.