Introduction to async views in Django | async/await in Django views

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ม.ค. 2025

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

  • @SharukhKhan-cq5zd
    @SharukhKhan-cq5zd 2 ปีที่แล้ว

    After Reading Documentation. I was confused. you did it very well. thanks from India...

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

    For Django 4.x - You need to change @sync_to_async to @sync_to_async(thread_sensitive=False) before get_stories_async() and get_movies_async() functions.
    Huge thanks to @ssadxuyui5060 who first commented the solution over a year ago in a reply.

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

      that was it! thank u!

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

      Thanks a lot man, I was really beginning to think I'm on the wrong side of a bad dream :)

  • @professionalfacepuncher8361
    @professionalfacepuncher8361 4 ปีที่แล้ว +10

    at last !! someone did an example video, I've been waiting so long for this
    (I've read the docs, but i wanted to know if i am doing things wrong, always better to watch an expert do things to get a perspective than just wing it)
    thanks alot man , subbed and liked.

    • @Pyplane
      @Pyplane  4 ปีที่แล้ว +3

      Thank you :) however if you want to see a real Django expert in action - check out Daniel Feldroy’s channel. I’m not an expert just a practicioner :)

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

      True! Luke is ahead of everybody😀

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

      @@Pyplane thanks for your humble recommendation will check it out

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

      DEP009 is some exciting stuff, async enabled querysets will be coming soon
      i'm just wondering what this will mean for the rest framework.

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

      Just had a question, can't we use async views in Django rest framework? Because serialization and other things happen there right?

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

    Finally, I found it. 😍😍. Please keep going. Take love.

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

      Hi Milon. Happy you're still here and very glad you liked the video. Cheers! :)

  • @sansinghsanjay
    @sansinghsanjay 2 ปีที่แล้ว +1

    Very nice, well-organized, and informative video. I got huge help by watching your other videos on Django. Thanks a lot for this wonderful work and please keep it up!

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

    Your tutorials are so good, I'm going to go through all of them :)

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

    Great explanation. Just add the "total" to the httpresponse instead of counting the seconds or searching the log. thumbs Up!

  • @Isaacv-mk3mi
    @Isaacv-mk3mi 4 ปีที่แล้ว

    can we use this with django rest projects?

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

    Was waiting for this. Great one

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

      Hi James. Thanks. Happy you liked it :)

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

    Finally async views. Great one 🔥

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

      Thank you Pabor! :)

  • @AbhishekBharadwaj-s1i
    @AbhishekBharadwaj-s1i ปีที่แล้ว

    When I define the post function in view as "async" like the async def main_view_async(), I keep getting this error:
    AssertionError: Expected a `Response`, `HttpResponse` or `HttpStreamingResponse` to be returned from the view, but received a ``
    What's the way around this?

  • @aashayamballi
    @aashayamballi 4 ปีที่แล้ว +3

    Hey Luke! This channel really deserve more and my suggestion would be give a tutorial on Brad Traversy's channel. People will definitely follow you here.
    Django 3.1 async views I was waiting for this tutorial and here we go... You never disappoint us.
    Keep up the good work Luke an never stop producing such a good tutorials.
    Many many thank you 🙏😊

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

      Thank you Aashay. Regarding the views on my channel - I know they aren’t spectacular, but I’m very happy :) I honestly didn’t believe I’ll get 1000 subscribers. As it is for Brad Travesy channel I have to first improve my english :) thanks a milion times for the support!

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

      @@Pyplane you're awesome!

  • @nareshkumar-mm3hq
    @nareshkumar-mm3hq 4 ปีที่แล้ว +1

    Many thanks Luke for @nother great video

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

      Thanks for watching Naresh! :)

  • @Shaunmcdonogh-shaunsurfing
    @Shaunmcdonogh-shaunsurfing 4 ปีที่แล้ว +1

    Great tutorial and thank you

  •  4 ปีที่แล้ว +4

    You should use `ab` to confirm that the async view would enable more requests to be handled as a effect of not blocking requests to execute while they wait for the io.

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

      what does ab mean?

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

    how to capture the return values from async get movie and async get stories in main view async

  • @АнатолийБугаков-е9г
    @АнатолийБугаков-е9г 3 ปีที่แล้ว

    Isn't Movie.objects.all() a sync function and hence blocks the requests?

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

    Bro i am uploading images on GCP and then create entry in database but when i run it. It is only create entry not upload image

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

    Thank you, What if i did not use with the await command, is it impossible (line 56)?

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

    How to get async function orm result send back to temple

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

    hi great tutorial as usual. i was finding something else and found you again. for example if we have 1000 requests data to show in template. can we show data of each request whenever request data returns like
    request 1: loading
    request 2: success here is your data value
    request 3: success here is your data value
    request4: loading
    request5: fail etc
    and each request is on different api
    . feel like real app data. need it very badly any guide or help ?

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

    very good tutorial , can i use async with class based views ? does django supports it ?

    • @stevemapes9672
      @stevemapes9672 2 ปีที่แล้ว +1

      In as of Django 3.1 - docs.djangoproject.com/en/4.1/topics/async/#async-views

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

    another great tutorial
    Respect.

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

      Thank you Muhammad :)

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

    how to apply this concept to a real world example?

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

    @Pyplane awesome 😈😈😈😈😈

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

    This is a most watch :)

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

    awesome as always. tq so much :-)

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

      thanks for watching :)

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

    Nice job

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

    thanks a lot mate keep the good work :)

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

      Thanks for watching :) cheers!

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

    Amazing!!!

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

      Thank you! 🙂

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

    I have a question that how we get data from database without refreshing page. Else ajax because i read in one video comment that it is not good way.

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

      I personaly don't work with ajax - the reason is that the code can get messy when building more advanced applications. For me a much better and easier way to do this is using django rest framework and react on the frontend. A tutorial on this will appear on the channel pretty soon. Cheers

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

      @@Pyplane i am waiting for this and django channel

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

      how much i wait for this..?

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

      @@NotBeHaris the seconda part of the crypto app will be released at the beginning of September :)

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

      AJAX or Websockets are the most common approach. The latter will be faster due to less network overhead

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

    I just ran your code and I am seeing same result..
    am i missing something..

    • @ИльяЯгупов-н4я
      @ИльяЯгупов-н4я 4 ปีที่แล้ว

      For me also the sync and async requests have the same execution time. I used the code from git.

    • @rodolfo4880-e4j
      @rodolfo4880-e4j 3 ปีที่แล้ว

      me too, what's going on?

    • @rodolfo4880-e4j
      @rodolfo4880-e4j 3 ปีที่แล้ว +2

      It works in django 3.1 but not django 3.2

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

      Also the same 7 secs regardless in Django 3.2

    • @DeepakKumar-uz4xy
      @DeepakKumar-uz4xy 3 ปีที่แล้ว

      @@rodolfo4880-e4j i am also using 3.1.2 verison but result is same.

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

    Thanks for this video.

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

      Thanks for watching :)

  • @DeepakKumar-uz4xy
    @DeepakKumar-uz4xy 3 ปีที่แล้ว

    i tried this but this is not working. sync to async function also running synchronously

  • @siya.abc123
    @siya.abc123 4 ปีที่แล้ว

    Dope video!

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

      Thank you!:)

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

    great video thank you Lukas.

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

      Hi Yuksel :) glad you liked it :))

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

      @@Pyplane improvements are always good, thank you. And by the way i made it trough by atthost, finally it worked .

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

      @@yukselbastan4687 Wowowow...congrats. That's a huge thing - make it work without knowing the Polish language. Congrats 100x !

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

      @@Pyplane thank you very much, you as our teacher you should become the thanks ;), just one question please, can i work years with atthost without any problems i mean should i make a 5 year payment ?

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

      @@yukselbastan4687 I don't know that :/ I pay annually each time

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

    Hi, I like this method. But, i have 1 doubt. It it necessary to wait for task to complete as my task will take around 30 minutes to complete.

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

      Hi. I don’t know the details of your task but maybe consider running it in the background? Cheers

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

      @@Pyplane hi, i want hep regarding this. my view takes more than 6 seconds but timeout happens in 5 secinds. how do i send http response first and then do processing. in this example it waits in both cases. i dont want to wait. return response first and then do things. it is possible using async

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

      @@ravikumarighare5297 use threading

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

      @@coolrezaul thanks. threading worked

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

    Thanks!

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

    Thanks Luke!

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

      Hi Daniel! Nice to hear from you again :) happy you liked the video :) Cheers!

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

      @@Pyplane ohh my friend. That's great you remember me! I've learnt a lot from you. Keep going!. Dziękuję Ci!

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

      @@danielaceros5723 Of course I do. My memory isn't perfect but I'll always remember the people who motivated me to carry on :) I am very happy and proud that you learned something from me :) Have a great day :) btw. nice Polish :))

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

    1.77K Subscribers nice :D

  • @amaangigani9372
    @amaangigani9372 2 ปีที่แล้ว +1

    Not working. Please update or remove this video

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

    Not really a good video. You doesn't explain very much, your toy example is too trivial to show something and also it just doesn't work as aspected. And yeah I saw the edited note about asyncio.sleep but if you can edit this you should have rather re-record this video.
    Cool that you make videos to show off new stuff but please more effort the net is full of broken toy examples like this. Personally I don't want that python becomes the next js in this regard.