How to Use Django Sessions

Sdílet
Vložit
  • čas přidán 6. 09. 2024
  • In this video I demonstrate how to use Django sessions by showing you how to create a recently viewed section in an ecommerce store.
    Need one-on-one help with your project? I can help through my coaching program. Learn more here: prettyprinted....
    Get the code here: prettyprinted....
    Twitter: / pretty_printed
    Github: github.com/pre...

Komentáře • 40

  • @AlexZyablov
    @AlexZyablov Před rokem +17

    For anybody who was searching for it. The actual tutorial about sessions starts at 14:12.

  • @davidinmichael
    @davidinmichael Před 9 měsíci +1

    This is a great tutorial, explains the whole concepts at once, thank you.

  • @amythomas3745
    @amythomas3745 Před 2 lety

    Thank you! I'm taking a programming bootcamp, am late with an assessment because after having all of the 'parts' for the website that I'm required to create, until watching this I just couldn't figure out how to correctly put it all together, the views, urls, etc, I finally get it! This wasn't even why I started watching it (I wanted to get a head start on the topic for Monday) but this was much more significant to me as far as actually having a chance to pass this course, I'm excited to watch the rest. thanks again!

  • @HandcartRule46
    @HandcartRule46 Před 2 lety +1

    Great video like always, the applicability of your tutorials is fantastic. If I may add a little tip, use constants when grabbing session data that way you ensure you didn't do a typo somewhere and will get an error in your ide. What i mean is instead of:
    request.session['data_field']
    Then:
    DATA_FIELD = 'data_field'
    request.session[DATA_FIELD]
    It works great when you are dealing with a lot of session data.

  • @brandon_wallace
    @brandon_wallace Před 2 lety

    Anthony, I really like these Django videos.

  • @vikaskumarl3719
    @vikaskumarl3719 Před 2 lety +1

    great video, nicely explained. Would have appreciated it even more if you had shown how the sessions are stored in DB and see what information does it store exactly.

    • @HandcartRule46
      @HandcartRule46 Před 2 lety

      I'm also keen to know about this. I've been wondering if you are able to save state with class based views for individual sessions.

  • @itsvivekshukla1
    @itsvivekshukla1 Před 2 lety

    to solve the issue that you faced in last part of the video, move the statement in line no 25 (insertion part) to the last part of current if (ie. right after removal of more than 5 elems). Nice Video. Thanks.

  • @ClaytonCook12
    @ClaytonCook12 Před 2 lety

    Really great video! Will be using sessions more now that I've seen how easy it is to add and remove data.

  • @itspaintosee
    @itspaintosee Před 8 měsíci

    I have the same set up (as far as I can tell). I'm using the django_session table. Which has no rows. But each time I have a new request, the session is empty. Anybody know why it's dictionary is either not being set or not being reloaded on follow up requests? Thanks

  • @ambaigbaig9459
    @ambaigbaig9459 Před 6 měsíci

    Pretty Printed why you didn't use orderby in order to manage the recently viewed image in the the list?

  • @akhils3561
    @akhils3561 Před 2 lety

    Nicely explained. if possible kindly do a video on soft deletion of data in django.

  • @saidtahmazov9197
    @saidtahmazov9197 Před 2 lety

    Really helpful video. Subscribed! Thanks.

  • @matrixtoogood5601
    @matrixtoogood5601 Před 2 lety +2

    Sessions start from 13:29

  • @AngelHernandez-ex7ji
    @AngelHernandez-ex7ji Před 2 lety +1

    how long do sessions last? is there a way to limit their time ?

  • @optimuseaacademy
    @optimuseaacademy Před rokem +1

    super tutorials, thanks man

  • @developershub2024
    @developershub2024 Před 4 měsíci

    Its a great video but i have a question, suppose we have a form where we are booking lets say a hotel but we did not finish the booking process, how can we make sure that after logging back in if we are logged in we dont loose the information in our form. instead we continue where we left. Someone please help.

    • @chahatbhatia2157
      @chahatbhatia2157 Před 2 měsíci

      I need help with the same, did u manage to get an answer?

  • @ajmalbangash6928
    @ajmalbangash6928 Před rokem

    Products.objects.filter(pk__n=request.sessions[recently_viewed])
    What is pk___n here refers to???

    • @prettyprinted
      @prettyprinted  Před rokem +1

      pk is the primary key of Products, so the product id. pk__in means that primary key matches of the items in the list request.sessions[recently_viewed]

  • @user-vv8sx2th6r
    @user-vv8sx2th6r Před rokem

    Thank you, it was realy interesting.

  • @MrPicklepod
    @MrPicklepod Před 2 lety

    A fantastic tutorial!

  • @thetechtimes
    @thetechtimes Před 2 lety +1

    Amazing ❤️✨

  • @RainSoundsToConcentrate
    @RainSoundsToConcentrate Před 4 měsíci

    Awesome :)

  • @2010sparsh
    @2010sparsh Před rokem

    Why would u add product to session ???

  • @timmanning9
    @timmanning9 Před 2 lety

    Is session synonymous with cookies? If not, what is the difference?

    • @prettyprinted
      @prettyprinted  Před 2 lety

      Sessions allow you to associate information with a user. A cookie is just one method of doing so. But I would say more implementation of sessions use cookies in some way.

  • @7s9n
    @7s9n Před 2 lety

    Thanks 💛

  • @idobooks909
    @idobooks909 Před rokem

    13:28

  • @AntonioSanchez-bi3nu
    @AntonioSanchez-bi3nu Před 2 lety

    Te amo.

  • @scren2010
    @scren2010 Před 2 lety

    👍

  • @chamaipornphongthong
    @chamaipornphongthong Před 2 lety

    👍👍👍👍👍👍👍

  • @ashokkumar5581
    @ashokkumar5581 Před rokem

    czcams.com/video/N-R5mT-nIDk/video.html for Sessions.