简体   繁体   中英

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.

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!

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' to INSTALLED_APPS and defining SITE_ID . Visit the admin site and be sure that the domain field of the Site 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):

  1. Add 'django.contrib.sites' to your INSTALLED_APPS setting.

  2. Define a SITE_ID setting:

     SITE_ID = 1
  3. 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM