注释表单在使用 Django-comments-xtd 时不加载



我是Django和Python的新手,正在尝试创建我的博客。我的设置包括运行在Windows 10上的Django 2.0.7和Python 3.6.5.我只配置了一个名为"personal"的应用程序。就我而言,页面加载"已发布 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>

删除注释表单标签周围的 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>

最新更新