`

Adding comments to Django blog.

06 FEB 2021

        If you have a blog and required medium for connecting with readers’ comments section is the best solution. The comments section on the blog is like a discussion platform. Readers can put forward their views and you can respond to them. There are numerous solutions available in the market. After a lot of experiments and research, I chose Telegram. This blog is about those experiments and my thinking process which lead me to telegram comments widget. It may help someone in dilemma phase right now.

       

         For bloggers and websites, comments are as important as the content on the site. Creating comments section is very straightforward these days. Many have already put their efforts into developing a solution. Today more confusion is about choosing best amongst the available options. If you are using WordPress or JOOMLA CMS you can simply add up a plugin, and on one click entire comments section gets ready to work. The design part is taken care of templates of the site.

 

        For Django, there are numerous developed solutions which are freely available. Unlike WordPress and JOOMLA, you have to play a little bit with code, i.e., models, templates and JavaScript. The benefit you get, it is more flexible than pre-designed plugins. With some logic development, you can have your own developed comments system with comments and replies functionality. If you are interested in your own experiments, refer the following link. It is a list of free as well-paid solutions.

 

Ref- https://djangopackages.org/grids/g/commenting/

 

        This system works very well when you have registered users or anonymous comments policy, both are extreme; no middle solution. But for blogs you can’t restrict readers for authentication; in case of anonymous comments, you can’t ensure the authenticity of comments. You do not want to ask readers to authenticate with username and password just for commenting purpose. For some precious content user may register with you and will definitely authenticate themselves for commenting also, people might pay for your content as well. Beginners require more time to establish themselves as such precious content creator. With these restrictions, you may want a solution which is easy to use for readers so that they don’t bounce off due to complicated comment’s part. There are paid solutions which handles storage, display and entire functionality part. You pay the price and can embed them with the help few JavaScript codes provided.

 

        If you are interested in free solutions then social media comments apps like Facebook and telegram are also available. Rather than free part I was looking for easy to handle comment part and utilising existing tools. So, I started researching Social media widgets. Both Facebook and Telegram provide easy to integrate solutions and looking at the subscriber count of both, people trust these solutions while commenting. Excluding WhatsApp after its recent controversy regarding business accounts. With just a few lines of code provided by these apps, your blog will be ready for comments. Facebook requires username and password to be entered before commenting on the other hand Telegram requires just phone number for comments. From personal experience I can say, it is easier to remember phone number rather than remembering username-password combination. Telegram does not ask for a password, you add your phone number for login, you get a confirmation message asking for confirmation on your phone number in telegram account. You press confirm and you can enter your comments.

 

      Let’s check out the telegram integration process, Facebook provides very detailed documentation with well-explained steps for their comment’s plugin. Refer the following link for Facebook comments plugin.

 

https://developers.facebook.com/docs/plugins/comments/

 

Telegram provides special comments app which is easy to integrate into any webpage.

 

1. Use the following link for creating your discussion app.

 

https://comments.app/

 

2. log in to discussion bot aka comments app

 

 

 

3. You will get a confirmation message on telegram account on your mobile phone. Press confirms you will be redirected to discussion bot aka comments app.

 

 

 

 

4. Click connect website button.

 

5. You will be redirected to website management page- Here enter your site name and domain. Click the Connect website.

 

 

 

6. You will get site ID which is system generated. 

 

7. You will be redirected to your site management page.

 

You are provided with site ID if you want you can change site name and domain and click save. 

 

Below there are two main options under Embed – Comments and Page ID. Comments option for how many comments you wish to display on your page. Height by default is Auto. You can experiment with various height options based on page design. Provide a unique URL of your page for page id and click enter.

 

8. Customize appearance as per your requirement.

 

 

 

9. On clicking enter you will get embed code like this.

 

<script async src="https://comments.app/js/widget.js?3" data-comments-app-website="siteid" data-limit="5"></script>

 

Add this script into the page where you want to display this comments app. Generally added at the bottom of the page.

 

 

 

 

Adding separate comments section per blog:

 

          There is no point in creating single comments section for the entire site which will be shared by all the blogs. Rather than engaging the reader, it will create confusion. Nobody will understand the context of comments unless the reader has read all the blogs. There are solutions available for separating comments per blog. Refer below my solution.

 

I prefer creating separate comments URLs under blog as follows:

class Blog(models.Model):

    title = models.CharField(max_length=250)

    date = models.DateTimeField()

    description = HTMLField(blank=True,null=True)

    urls=models.CharField(max_length=500,blank=True,null=True)

    comments=models.CharField(max_length=500,blank=True,null=True) 

 

Above code is for model.py from blogs app.

 

As I have a site with dash apps I have separated normal blogs with dash app blogs with the help of URL. In the comment section, I am storing the following script

 

<script async src="https://comments.app/js/widget.js?3" data-comments-app-website="siteid" data-limit="5"></script>

 

Following code is used for displaying comments in the template

{% if blog.comments %}

                <div class="row">

                {{ blog.comments|safe }}

                </div>

{% endif %}

 

Use as many comments sections you require using telegram app. Simply add javascript code into the comments field of the blog model. 

   

     Done! You are successfully added comments app to your webpage. Login and enter your comments.

 

If you are unable to see comments box after login. It means your browser is blocking third-party cookies. Enable third party cookies for page and box will be visible.

 

Check my site to see this comments app in action.

https://datarabbit.in/blog/blog/TargetVsAchievements

 

Ref - https://core.telegram.org/widgets/discussion