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

Attempting to add a new reply fails with TemplateDoesNotExist at /comments/reply/1/ base.html #238

Closed uhexos closed 3 years ago

uhexos commented 3 years ago

After brand new install, adding comments works just fine but attempting to reply to a comment gives TemplateDoesNotExist at /comments/reply/1/ base.html. I have no template in my directory structure called base.html and adding one to my project which extends my current template just throws even more TemplateDoesNotExist errors.

TemplateDoesNotExist at /comments/reply/1/
django_comments_xtd/hostel/room/reply.html, django_comments_xtd/hostel/reply.html, django_comments_xtd/reply.html

Sample Entry Template File.

{% extends 'hostel/index.html' %} 
{% load static %}
{% load columns %}
{% load i18n %}
{% load comments %}
{% load comments_xtd %}

{% block content %}
        <div class="card-body">
            {% render_comment_form for room %}
            {% render_comment_list for object %}
        </div>
{% endblock content %}

{% block owner_id %}{{owner.id}}{% endblock owner_id %}

Also added a comments folder to my templates directory and made a new reply.html file with contents as below copied form the packages own reply.html but i still get the same errors as above. How am I supposed to set this package up to use my own equivalent of a base.html since I dont have such a file and currently have no need for one. All my attempts so far have failed and I cant seem to find it in the docs.

SAMPLE REPLY.HTML TEMPLATE

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

{% block title %}{% trans "Comment reply" %}{% endblock %}

{% block content %}
<div class="container">
  <div class="mb-4">
    <h3 class="text-center">{% trans "Reply to comment" %}</h3>
    <hr/>
  </div>
  <div class="row">
    <div class="offset-md-1 col-md-10">
      <div class="media">
        <div class="mr-3">{{ comment.user_email|xtd_comment_gravatar }}</div>
        <div class="media-body">
          <div class="comment pb-3">
            <h6 class="mb-1 small">
              {{ comment.submit_date|date:"N j, Y, P" }}&nbsp;-&nbsp;
              {% if comment.user_url %}
              <a href="{{ comment.user_url }}" target="_new">{% endif %}
                {{ comment.user_name }}{% if comment.user_url %}</a>{% endif %}
            </h6>
            <p>{{ comment.comment }}</p>
          </div>
        </div>
      </div>
      <div class="card mt-4 mb-5">
        <div class="card-body">
          <h4 class="card-title text-center pb-3">{% trans "Post your comment" %}</h4>
          {% include "comments/form.html" %}
        </div>
      </div>
    </div>
  </div>
</div>
{% endblock %}
{% load i18n %}
{% load comments %}
{% load comments_xtd %}

{% block title %}{% trans "Comment reply" %}{% endblock %}

{% block content %}
<div class="container">
  <div class="mb-4">
    <h3 class="text-center">{% trans "Reply to comment" %}</h3>
    <hr/>
  </div>
  <div class="row">
    <div class="offset-md-1 col-md-10">
      <div class="media">
        <div class="mr-3">{{ comment.user_email|xtd_comment_gravatar }}</div>
        <div class="media-body">
          <div class="comment pb-3">
            <h6 class="mb-1 small">
              {{ comment.submit_date|date:"N j, Y, P" }}&nbsp;-&nbsp;
              {% if comment.user_url %}
              <a href="{{ comment.user_url }}" target="_new">{% endif %}
                {{ comment.user_name }}{% if comment.user_url %}</a>{% endif %}
            </h6>
            <p>{{ comment.comment }}</p>
          </div>
        </div>
      </div>
      <div class="card mt-4 mb-5">
        <div class="card-body">
          <h4 class="card-title text-center pb-3">{% trans "Post your comment" %}</h4>
          {% include "comments/form.html" %}
        </div>
      </div>
    </div>
  </div>
</div>
{% endblock %}

165 talked about a similar issue but the answer given made no real sense to me

danirus commented 3 years ago

The template content you posted here is duplicated. That must be giving already a lot of errors. Once you fix that, if the issue is still about the base.html template, you could either:

  1. Create a base.html template in your templates directory, like templates/django_comments_xtd/base.html, or
  2. Provide your own reply.html template in any of the directories you got listed: django_comments_xtd/hostel/room/reply.html, django_comments_xtd/hostel/reply.html or django_comments_xtd/reply.html.
  3. Stop and start the runserver command to reload template changes.

Try running the demo projects and see how they have the templates organized. The comp demo site is available as a Docker image too. See the repo and instructions here.

uhexos commented 3 years ago

With regards to your 2nd suggestions those Paths are inside the venv folder are you recommending I edit those directories ?

uhexos commented 3 years ago

Creating a directory as templates/django_comments_xtd/reply.html has fixed the issue. However the documentation states that the folder should be called comments comments instead of django_comments_xtd don't know if this is correct. However changing the name fixed the issue I was facing thanks

danirus commented 3 years ago

No. In your Django project settings module you must have an entry called TEMPLATES. That entry may have a DIRS entry (not to be confused with APP_DIRS, see the example here). Having APPS_DIR: True makes Django use the templates installed within the app (which is in your virtualenv), but if you want to replace any of those templates you need to put them in your own template directory, the one in the DIRS setting within TEMPLATES.

uhexos commented 3 years ago

Ended up just abandoning the package as every page required me to make a custom template then randomly my server started requesting all the bootstrap mixins instead of just using the min file.

tian-yan commented 2 years ago

@uhexos I am having the same issue and planning to abandoning the package, do you have any good alternatives to share ? I am using TailwindCSS, not bootstrap, which makes situation even worse.

yuis-ice commented 2 years ago

umm I have the same problem.

danirus commented 2 years ago

Hi, the code in the branch rel-3.0.0 is 99,9% ready. It does not use Bootstrap nor any other framework. This new version 3.0 does not use the render_xtdcomments_tree but rather a render_xtdcomment_list, so it is not backward compatible. There are two example sites in the demos/ that you can use to test it. The new version does not come with the reactJs plugin, but rather a few vanilla JavaScript modules to send comments, replies and comment reactions. If you want to give it a try and want to make questions, I will be glad to answer them in the Discussions.