[英]Django Commenting Errors
I am new to Django and was working on my blog site to include a comment feature by using django-comments-xtd package.我是 Django 的新手,并且正在我的博客网站上使用 django-comments-xtd package 包含评论功能。
I was following the tutorials specified on "https://django-comments-xtd.readthedocs.io/en/latest/tutorial.html", but it kept giving me an error saying "DoesNotExist at /comments/post/" whenever I tried to submit any comment我正在按照“https://django-comments-xtd.readthedocs.io/en/latest/tutorial.html”上指定的教程进行操作,但每当我出现“DoesNotExist at /comments/post/”时,它总是给我一个错误试图提交任何评论
This is comment section code from my blog template from DetailView:这是来自 DetailView 我的博客模板的评论部分代码:
{% if comment_count %}
<hr/>
<div class="comments">
{% render_comment_list for object %}
</div>
{% endif %}
<div class="card card-block mb-5">
<div class="card-body">
<h4 class="card-title text-center pb-3">Post your comment</h4>
{% render_comment_form for object %}
</div>
</div>
This is my DetailView called PostDV:这是我的名为 PostDV 的 DetailView:
class PostDV(DetailView):
model = BlogModel
And this is the error which I am getting right now:这是我现在遇到的错误:
DoesNotExist at /comments/post/
Site matching query does not exist.
Request Method: POST
Request URL: http://127.0.0.1:8000/comments/post/
Django Version: 3.1.6
Exception Type: DoesNotExist
Exception Value: Site matching query does not exist.
During handling of the above exception (Site matching query does not exist.), another exception occurred:
comment = form.get_comment_object(site_id=get_current_site(request).id)
Does anybody had this kind of issue before?以前有人遇到过这种问题吗? Thank you very much for your help!非常感谢您的帮助!
As stated in the second point in the quickstart guide [django-comments-xtd Docs] of the package you use:如您使用的 package 的快速入门指南 [django-comments-xtd Docs]中的第二点所述:
Enable the “sites” framework by adding
'django.contrib.sites'
toINSTALLED_APPS
and definingSITE_ID
.通过将'django.contrib.sites'
添加到INSTALLED_APPS
并定义SITE_ID
来启用“站点”框架。 Visit the admin site and be sure that the domain field of theSite
instance points to the correct domain (localhost:8000
when running the default development server), as it will be used to create comment verification URLs, follow-up cancellations, etc.访问管理站点并确保Site
实例的 domain 字段指向正确的域(运行默认开发服务器时为localhost:8000
),因为它将用于创建评论验证 URL、后续取消等。
You need to enable the sites framework, set the SITE_ID
setting and make sure the domain is correctly saved.您需要启用站点框架,设置SITE_ID
设置并确保正确保存域。 To do this as referred in Django's documentation (linked in above quote):要按照 Django 文档中的说明执行此操作(在上面的引用中链接):
Add 'django.contrib.sites' to your INSTALLED_APPS setting.将“django.contrib.sites”添加到您的INSTALLED_APPS设置中。
Define a SITE_ID setting:定义SITE_ID设置:
SITE_ID = 1
After which go to the admin site and edit the Site object which would be created to have the correct domain for your server (In development localhost:8000
or 127.0.0.1:8000
, etc., In production it depends on your site)之后 go 到管理站点并编辑站点 object 将创建为您的服务器具有正确的域(在开发中localhost:8000
或127.0.0.1:8000
等,在生产中取决于您的站点)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.