How To Create an Unlike Blog Button - Django Blog #19

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 ก.ย. 2024

ความคิดเห็น • 90

  • @Codemycom
    @Codemycom  4 ปีที่แล้ว +1

    ▶️ Watch Entire Django Blog Playlist ✅ Subscribe To My TH-cam Channel:
    bit.ly/3bWN6wj bit.ly/2IGzvOR
    ▶️ See More At: ✅ Join My Facebook Group:
    Codemy.com bit.ly/2GFmOBz
    ▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt!
    Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN

    • @tinkuprasad2288
      @tinkuprasad2288 4 ปีที่แล้ว

      How can we add like button in home or index view?? Is it possible...I tried but didnt work for me...

  • @D000023
    @D000023 3 ปีที่แล้ว +10

    actually we don't need to calculate total_likes and liked variables in views and pass them to template. all of it can be done in template itself:
    number of likes:
    likes: {{ post.likes.count }}
    button (filled or outlined depending on if post is liked or not)
    Like

    • @darwinsterritory
      @darwinsterritory 3 ปีที่แล้ว

      Thanks bro it's a perfectly)

    • @mrbuslov
      @mrbuslov 3 ปีที่แล้ว

      @@darwinsterritory Thanks a lot! You really helped me!

    • @darwinsterritory
      @darwinsterritory 3 ปีที่แล้ว

      @@mrbuslov Мне то за что :D

    • @mrbuslov
      @mrbuslov 3 ปีที่แล้ว +1

      @@darwinsterritory Хаха, прости, не на то ответил)

    • @mrbuslov
      @mrbuslov 3 ปีที่แล้ว

      Thank you! You really helped me

  • @alexradu1921
    @alexradu1921 4 ปีที่แล้ว +5

    Hello nice video!
    One tip: after log in it would be nice for user to be redirected to that blog post. So if anyone wonders how, this works:
    Log in to like this article!

  • @randyk7238
    @randyk7238 3 ปีที่แล้ว +5

    Having a great time learning. its so easy and simple with pure python.

  • @PhillyEastSide
    @PhillyEastSide 3 ปีที่แล้ว +2

    Absolutely love this series and really appreciate you uploading it all on YT.
    One quick question. If I want to display the number of dislikes a post garners from other users, will I have to build a 'copy' of this structure but purely for dislikes... or is there a 'quick fix' method?
    Still a noob myself and thought I'd ask here if anyone has tackled this before (I will also attempt it on my own with the 'copy' of the same structure so that I end up with a system to display 'likes' and 'dislikes')

  • @Razilator
    @Razilator 4 ปีที่แล้ว +2

    Thanks bro! I am Russian, but I watch your vidos. Thank!

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      Glad to hear that

  • @sakibshabir1785
    @sakibshabir1785 4 ปีที่แล้ว +1

    how can we add other db??like postgresql..would u please make a video on that

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว +1

      Just add it to your settings.py file

  • @nicolastabin8147
    @nicolastabin8147 4 ปีที่แล้ว +1

    MAN I FUCKING LOVE YOU! YOU'RE BUENARDO! Greetings from Argentina

  • @Hosseinsarpanah
    @Hosseinsarpanah 4 ปีที่แล้ว +1

    Thanks for your video. I guess using jQuery could be a better solution as HttpResponseRedirect is rendering and refreshing all the template for just a like/dislike event.

  • @chrismartel1039
    @chrismartel1039 4 ปีที่แล้ว

    post.likes.filter(id=request.user.id) is weird, it must of been post.likes.filter(user=request.user.id) 😐

  • @VitaliiPodhornyi
    @VitaliiPodhornyi 2 ปีที่แล้ว

    I get a error
    stuff = get_object_or_404(Post, id=self.kwargs['pk'])
    KeyError: 'pk'
    please can someone to fix it?

  • @elmacron19
    @elmacron19 2 ปีที่แล้ว

    I'm getting an error ('ManyToManyDescriptor' object has no attribute 'filter') when I click the dislike button any idea why?

    • @Codemycom
      @Codemycom  2 ปีที่แล้ว

      What did you do differently from the video?

  • @rad.strums
    @rad.strums 4 ปีที่แล้ว +1

    Hi I am getting this error on pressing the unlike button :
    No Post matches the given query.
    You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
    Plz help

    • @rad.strums
      @rad.strums 4 ปีที่แล้ว

      if I set DEBUG = False
      Then it gives allowed hosts error, If I set allowed hosts = ['*']
      then also it doesn't work

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      You have a typo in your code somewhere...recheck your steps

    • @rad.strums
      @rad.strums 4 ปีที่แล้ว

      No, the like thing works fine, but when I press the unlike again this comes.

    • @rad.strums
      @rad.strums 4 ปีที่แล้ว

      @@abhishekbobbillapati692 help plz.

    • @rad.strums
      @rad.strums 4 ปีที่แล้ว

      @@abhishekbobbillapati692 heyyy!!!! would you mind , helping me out with this ?

  • @scoryjf1154
    @scoryjf1154 ปีที่แล้ว

    Thanks a lot for all. I don't understand the "liked" in LikeView : no effect.

  • @ciaook4017
    @ciaook4017 2 ปีที่แล้ว

    I need help for my app Django.
    My aim is that, when I publish my posts through the administration panel, they must automatically appear on index.html, without refreshing the page.
    I tried to use Ajax and Websocket, but they only continually recharhe the DIV.
    Is there another way?

  • @allenjoshuafrancisco7128
    @allenjoshuafrancisco7128 4 ปีที่แล้ว +1

    Would you make a video on how to add photo/s and or video/s to a blog post? Thank you in advance :)

  • @ranbirkapoor7291
    @ranbirkapoor7291 4 ปีที่แล้ว

    UnboundLocalError at /article/4
    local variable 'liked' referenced before assignment - getting this error what to do sir?

  • @bigsandip
    @bigsandip 4 ปีที่แล้ว +1

    These (like ,unlike)are the videos I was waiting for.please do video for save button too

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      save what?

    • @bigsandip
      @bigsandip 4 ปีที่แล้ว

      Codemy.com I mean like reddit.save blog for future reference

  • @danielviera9145
    @danielviera9145 4 ปีที่แล้ว +1

    thanks a lot!! Extremely helpful!

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      Glad it helped!

  • @siddheshpawar9032
    @siddheshpawar9032 3 ปีที่แล้ว

    I am getting "HTTP ERROR 405" when I click Like button

  • @ai.201
    @ai.201 2 ปีที่แล้ว

    When I'm hiding the author field, I'm getting this error hidden field author select a valid choice

  • @bhupeshpathak9316
    @bhupeshpathak9316 4 ปีที่แล้ว

    Hello sir
    Can you make like dislike buttons like TH-cam i.e if user likes the post the like counts gets increased n if dislike the dislike count will increase.... user can either like or dislike post

  • @golodiassaid4879
    @golodiassaid4879 2 ปีที่แล้ว

    How can you avoid refresh? otherwise it would be difficult for users to comeback to where they were after page refresh

  • @kalokola
    @kalokola 3 ปีที่แล้ว

    Am actually getting as Bachelors in Django from here 😊

  • @slavkodem70
    @slavkodem70 4 ปีที่แล้ว +1

    Thanks dude, very helpful

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      Glad it helped

    • @kalokola
      @kalokola 3 ปีที่แล้ว

      too helpful

  • @ahmedkhairy482
    @ahmedkhairy482 4 ปีที่แล้ว +1

    Great video! Can you add a like button also along with the count in the list of posts view instead of limiting it to going to the detail view of the post?

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว +1

      Sure...but why not try it yourself. You have the tools now.

    • @ahmedkhairy482
      @ahmedkhairy482 4 ปีที่แล้ว

      @@Codemycom I will, thanks a lot really good video! One quick question is there a solution to avoid the page refreshing every time you like a post?

    • @alexradu1921
      @alexradu1921 4 ปีที่แล้ว

      @@ahmedkhairy482 not really.. only if you give up all of this simple method and get AJAX.js integrated.

    • @descubriendopatronesML
      @descubriendopatronesML 2 ปีที่แล้ว

      @@ahmedkhairy482 django channels

  • @AttentionModeHumbleEst2022
    @AttentionModeHumbleEst2022 3 ปีที่แล้ว

    Isn't then the liked in LikeView useless? I deleted it and it worked the same.

  • @austinflatt3210
    @austinflatt3210 3 ปีที่แล้ว

    How can we list the users usernames who liked the post?

  • @mehmetali1945
    @mehmetali1945 4 ปีที่แล้ว

    i can easily say i totally didn't understand the function get_object_data ,frontend backend thing, Is it normal for a beginner(its been 1 month)? should i just copy paste some code to get use to it?

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      probably :-p

  • @dradrigapatrick
    @dradrigapatrick 4 ปีที่แล้ว

    Today`s Friday had a great explanation moment !!!!!
    Well explained.
    Thank you.

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      Glad you liked it!

  • @giwakausarat164
    @giwakausarat164 2 ปีที่แล้ว

    Nice video

  • @heroCode20
    @heroCode20 หลายเดือนก่อน

    ❤❤❤❤

    • @Codemycom
      @Codemycom  25 วันที่ผ่านมา

      thanks

  • @gamerstrim
    @gamerstrim 4 ปีที่แล้ว

    I can't make comments under the post. Can you do this in next video?

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      I'll likely look at comments eventually

  • @simpletechtips8442
    @simpletechtips8442 4 ปีที่แล้ว

    I added one additional layer. A user should not be able to like their own post, so after the "if user.is_authenticated" I added another "if user.id != post.author.id" and place your buttons inside that block.
    Don't forget your "endif" before your "else" of the "user.is_authenticated" block

  • @randhirgupta9518
    @randhirgupta9518 3 ปีที่แล้ว

    i am watching this video today and guess what it's Friday

  • @kalokola
    @kalokola 3 ปีที่แล้ว

    where can I get a complete code for these tutorials

    • @Codemycom
      @Codemycom  3 ปีที่แล้ว

      github.com/flatplanet/djangoblog

  • @shawnbeans7389
    @shawnbeans7389 3 ปีที่แล้ว

    Noice.

  • @theglammcoder
    @theglammcoder 4 ปีที่แล้ว

    I am trying to add a like button and a dislike button just like we have on youtube but couldn't able to do it ?? anyone can help me oout ??

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      What problem are you having? Can you rewatch the video and follow along?

    • @theglammcoder
      @theglammcoder 4 ปีที่แล้ว

      @@Codemycom just like you created a like button and than add a condition so it changes into dislike according to that i tried the same but its not changing into dislike..
      {% csrf_token %}
      {% if is_liked %}

      {% else %}

      {% endif %}
      {{ post.total_likes }} Likes

    • @simpletechtips8442
      @simpletechtips8442 4 ปีที่แล้ว

      @@theglammcoder To accomplish this, I actually created another form for the dislikes.
      That does mean that I also needed to modify the models.py, views.py and urls.py accordingly. Give it a try. If you still don't have it, post here again, and I will share more. I also needed to migrate my database again due to the change in the models.py. I have not yet set it so you cannot both like and dislike a post, but it's getting late and I need to stop for the night.

  • @avishkarhande
    @avishkarhande 4 ปีที่แล้ว

    hey, would you please make a video or share some reference on how to add the like unlike buttons on the HomeView I'm kinda not able to add those buttons in HomeView...

    • @avishkarhande
      @avishkarhande 4 ปีที่แล้ว

      i'm facing keyerror at pk if i try doing code in HomeView Class

    • @samixpunch9678
      @samixpunch9678 3 ปีที่แล้ว

      @@avishkarhande I did it, do you still want the solution ?

    • @SLimerated
      @SLimerated 3 ปีที่แล้ว

      @@samixpunch9678 hi! I would really like to know how you did it please. ive been having trouble doing it

    • @samixpunch9678
      @samixpunch9678 3 ปีที่แล้ว

      @@SLimerated You have a discord ? Add me SamiNur#9889

  • @ahmedkhairy482
    @ahmedkhairy482 4 ปีที่แล้ว

    When is the next video?

  • @chethanmgowda8718
    @chethanmgowda8718 4 ปีที่แล้ว

    Wait for next vedio... In blog series....

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว +1

      I got bored with it...I'll get back to it in a week or so

    • @Confusedcapybara8772
      @Confusedcapybara8772 4 ปีที่แล้ว +1

      Codemy.com can I vote for maybe how to host or add google analytics 🙂

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว +1

      @@Confusedcapybara8772 not a bad idea