Reputation: 69
I am new to Django and was working on my blog site to include a comment feature by using 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
This is comment section code from my blog template from 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:
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!
Upvotes: 0
Views: 215
Reputation: 21822
As stated in the second point in the quickstart guide [django-comments-xtd Docs] of the package you use:
Enable the “sites” framework by adding
'django.contrib.sites'
toINSTALLED_APPS
and definingSITE_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.
You need to enable the sites framework, set the SITE_ID
setting and make sure the domain is correctly saved. To do this as referred in Django's documentation (linked in above quote):
Add 'django.contrib.sites' to your INSTALLED_APPS setting.
Define a SITE_ID setting:
SITE_ID = 1
Run migrate.
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)
Upvotes: 2