Learn Django - An AJAX Like button feature within the Django Framework - Django Tutorial

preview_player
Показать описание
In this Django tutorial we work through developing a Django AJAX Like button feature for our existing Blog. This Django tutorial is part 11 of the building a simple blog series. The base code I use in this tutorial can be downloaded using the link in the description below.

00:00 Introduction
01:00 Preview of final development
01:50 How to get started - see code and instructions below
03:03 Create a new fields in the blog model
06:08 Developing the template
10:07 Working with AJAX (Remember to replace/update jQuery)
10:54 AJAX walk-through
13:12 Developing the view
19:48 Back to the template to finish off
24:06 Some final tests

Need help downloading and starting the code?
=================================================
Tutorial - How to download and run the code (must have Python installed)
=================================================

Code Repository (Part10)

Code Repository (Part11)

SUBSCRIBE to get more free tutorials, courses and code snippets!

Follow us on Facebook

Follow use on Twitter:
Рекомендации по теме
Комментарии
Автор

Your channel really is so helpful honestly. Your videos are very well-explained and broken down and always seems to fit with exactly what I’m looking for. Thank you, your efforts are very much appreciated.

sarchi-xo
Автор

I've been searching the web for an easy explanation of how to implement AJAX into Django for a project I've been working on.
This has been a Godsend! Thank you.
As the previous poster mentioned, I am not really familiar with AJAX either. It would be great to see you go through that a little more too.
I think I'll be spending a lot more time on your channel from now!

AliMulla
Автор

Good tutorial sir, I am following your django rest framework with react project. I just decided to take look at what you did and I love it. alot to learn again in django.

bagurashamuddeen
Автор

Sir you're on fire. Like/Unlike is very essential in modern day blog app. Love this. But Ajax is difficult for me to comprehend, but i think doesn't really matter, as long as I can use it to get the job done. I'll do your J.S courses after am done with Django.

paborlouise
Автор

@veryacademy you are simply awesome. ✊🏿👌👍🏿👍🏿👍🏿
I am liking every comments here.

michealnd
Автор

I found your tutorial clear and informative. I modified this so that the one could like the post without navigating to the detail page. However, I discovered that users can only like posts on the first paginated page. On subsequent pages, the "like" button is not clickable.

andrewfry
Автор

Awesome content! You definitely got a new subscriber

tdubs
Автор

Hello! Thanks for the code.
Got an error "Forbidden (CSRF token missing or incorrect.): /like/"
To make it work I've added {% csrf_token %} before <button id="like-button">....

vitalii_myt
Автор

Well this is working for a single post but when i try this thing in post list template than i was unable to like other posts except the first one, why so ? does this thing only work for single post.?

InspirePlayCrypto
Автор

running into an issue, how could i apply the ajax onto a list view with more than 1 post on the page? currently only the top post will get liked even if im clicking on the second or third posts' like button. I suspect this is because the script is not able to differentiate between the different post id's

bbcwccccc
Автор

After implementing the ajax button, which works flawlessly, my comment section gives ValueError: Field 'id' expected a number but got. Could be something about having more than one id? Any idea?

Gsnchez
Автор

Man this is awesome. Thank you bro. How did you learn how to do this stuff?

sheriffcrandy
Автор

Wow....Great videos since last couple of days....m having a hard time to keep up with your speed....certainly you are on fire to catch up with you soon :)

codedjango
Автор

this is really a great series and you are a great teacher. Whenever you have time, please make a video on how to integrate redis with django. I think this like system could use redis to offload the database, but I don't have any idea how to do it.

georgesmith
Автор

This is a great piece of work. Could you please add color-change when a user like or unlike a post, too?

Troglodyte
Автор

Very good tutorial! One of the best I've found! Share your tutorials on my blog to! Tell me pls, which is the best way to prevent a visitor like same post many times? For example, storing ip from a time is a good option?

mihaid
Автор

1 question pls : what if i want to create a separated Like model that have a manyToMany users field and and post as a foreignKey field .... How can i get the total likes from the Post Model???

medazizchagour
Автор

why is my button not working, i did everything as you taught but it doesn't produce the result. there are no error .
nothing in the console either .is there a way to solve this.

anilshrestha
Автор

Great video, but when I click on the like button, it returns a 404 error localhost:8000/like/ not found, do you have any idea why? Thanks

Oliwonderfr
Автор

In the views file, on line 22, the code is -- id =

When I run the server and click on the button, I get an error code that says
ValueError: invalid literal for int() with base 10:
I have made some very small changes to the logic of my page since I am including and upvote and a downvote instead of a like button.
The problem seems to be with the ID being passed into the view.
Any ideas? would be greatly appreciated.

AliMulla