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

Поделиться
HTML-код
  • Опубликовано: 12 дек 2024

Комментарии • 94

  • @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?

  • @SharukhKhan-cq5zd
    @SharukhKhan-cq5zd 2 года назад

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

  • @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!

  • @gregcompton9631
    @gregcompton9631 Год назад +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 Год назад

      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 :)

  • @MrValVet
    @MrValVet Год назад

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

  • @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! :)

  •  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.

  • @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

  • @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!

  • @rramos550
    @rramos550 2 года назад

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

  • @NotBeHaris
    @NotBeHaris 4 года назад +1

    another great tutorial
    Respect.

    • @Pyplane
      @Pyplane  4 года назад

      Thank you Muhammad :)

  • @bentwite3093
    @bentwite3093 4 года назад +1

    This is a most watch :)

  • @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

  • @Isaacv-mk3mi
    @Isaacv-mk3mi 4 года назад

    can we use this with django rest projects?

  • @seandenny6430
    @seandenny6430 4 года назад +1

    Amazing!!!

    • @Pyplane
      @Pyplane  4 года назад

      Thank you! 🙂

  • @rajughorai3909
    @rajughorai3909 4 года назад

    Thanks for this video.

    • @Pyplane
      @Pyplane  4 года назад

      Thanks for watching :)

  • @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?

  • @zorojuro5106
    @zorojuro5106 4 года назад

    thanks a lot mate keep the good work :)

    • @Pyplane
      @Pyplane  4 года назад

      Thanks for watching :) cheers!

  • @rangabharath4253
    @rangabharath4253 4 года назад

    awesome as always. tq so much :-)

    • @Pyplane
      @Pyplane  4 года назад

      thanks for watching :)

  • @siya.abc123
    @siya.abc123 4 года назад

    Dope video!

    • @Pyplane
      @Pyplane  4 года назад

      Thank you!:)

  • @JustPython
    @JustPython Год назад

    Nice job

  • @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

  • @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 ?

  • @pinchasnachmani1418
    @pinchasnachmani1418 3 года назад

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

  • @АнатолийБугаков-е9г

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

  • @vaibhavgupta4413
    @vaibhavgupta4413 4 года назад +1

    @Pyplane awesome 😈😈😈😈😈

  • @jayachandraB
    @jayachandraB 3 года назад

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

  • @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 :))

  • @ckom9
    @ckom9 3 года назад

    Thanks!

  • @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

  • @wilmerferneycubidesporras7774
    @wilmerferneycubidesporras7774 3 года назад

    how to apply this concept to a real world example?

  • @dgiri2333
    @dgiri2333 Год назад

    How to get async function orm result send back to temple

  • @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

  • @DeepakKumar-uz4xy
    @DeepakKumar-uz4xy 3 года назад

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

  • @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 3 года назад +2

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

    • @ИльяЯгупов-н4я
      @ИльяЯгупов-н4я 3 года назад

      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.

  • @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.