使用django-comments-xtd时不会加载注释表单

时间:2018-08-15 14:01:41

标签: python html django django-comments

我对Django和Python还是陌生的,并且正在尝试创建我的博客。我的设置包括在Windows 10上运行的Django 2.0.7和Python 3.6.5。我仅配置了一个名为“个人”的应用。如果该页面加载了“已发布0条评论”,并且该页面未呈现评论表单。

下面是我的代码段

settings.py 配置

INSTALLED_APPS = [
    'personal',
    'django.contrib.sites',
    'django_comments_xtd',
    'django_comments',
]

COMMENTS_APP = "django_comments_xtd"
COMMENTS_XTD_CONFIRM_EMAIL = True 
COMMENTS_XTD_SALT = b"es-war-einmal-una-bella-princesa-in-a-beautiful-castle"
COMMENTS_XTD_FROM_EMAIL = 'noreply@example.com'
COMMENTS_XTD_CONTACT_EMAIL = 'helpdesk@example.com'
COMMENTS_XTD_MAX_THREAD_LEVEL = 0 
COMMENTS_XTD_THREADED_EMAILS = False

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.mail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = 'noreply@example.com'
EMAIL_HOST_PASSWORD = 'abcd1234'

urls.py (个人应用下的urls.py)

urlpatterns = [
  ........................
  ........................
    url(r'^comments/', include('django_comments_xtd.urls')),

    ]

models.py (under personal app)

from django.db import models

class mycomments(models.Model):

   mail = models.CharField(max_length = 50)
   name = models.CharField(max_length = 50)
   phonenumber = models.IntegerField()

   class Meta:
      db_table = "mycomments"

观看次数(在个人应用下)

def page1(request):
    mycomm =Recipiecomments()
    return render(request, 'personal/blackforestcake.html',locals())

最后是 page_detail.html

<!DOCTYPE HTML>
<html>
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>My Page</title>


{% load static %}   

    </head>
    <body>

    <div class="fh5co-loader"></div>

    <div id="page">
    {% include 'personal/head.html' %}
    {% load comments %}
    {% load comments_xtd %}


    <div id="fh5co-author">
        <div class="container">
            <div class="row top-line animate-box">
                <div class="col-md-8 col-md-offset-2">
                    <h2>My Blog detail</h2>     
                </div>
            </div>
            <div class="row">
                <div class="col-md-8 col-md-offset-2">
                    <p class="animate-box"><img src="{% static "personal/img/pic" %}" class="img-responsive" alt="image"></p>
                    <div class="testimony animate-box">
                        <blockquote>
                        <h3>Topic 1:</h3>
                        <ul>
                            <li>Detail 1</li>
                                               </ul>
                        </blockquote>
                    </div>

{% get_comment_count for mycomm as comment_count %}
 &nbsp;&sdot;&nbsp;
 {{ comment_count }} comments have been posted.
</div>

{% if mycomm.allow_comments %}
<div class="comment">
  <h4 class="text-center">Your comment</h4>
  <div class="well">
    {% render_comment_form for mycomm %}
  </div>
</div>
{% endif %}

{% if comment_count %}
<hr/>
<ul class="media-list">
  {% render_xtdcomment_tree for mycomm %}
</ul>
{% endif %}

    </div>

    <div class="gototop js-top">
        <a href="#" class="js-gotop"><i class="icon-arrow-up"></i></a>
    </div>


    </body>
</html>

1 个答案:

答案 0 :(得分:0)

删除注释表单标签周围的if标签,即

{% if mycomm.allow_comments %}
<div class="comment">
  <h4 class="text-center">Your comment</h4>
  <div class="well">
    {% render_comment_form for mycomm %}
  </div>
</div>
{% endif %}

现在应该是

<div class="comment">
  <h4 class="text-center">Your comment</h4>
  <div class="well">
    {% render_comment_form for mycomm %}
  </div>
</div>