Add Product To Cart - Django Wednesdays ECommerce 13

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ก.ค. 2024
  • In this video I'll show you how to add products to the shopping cart.
    We want customers to be able to click on an item and add that to our Shopping Cart.
    We also want to keep track of those items if they leave the site and come back later.
    Sessions will allow us to do that, and Javascript and JQuery will help us out...
    #django #codemy #JohnElder
    Timecodes
    0:00​​ - Introduction
    1:00 - Add JQuery To App
    2:10 - Add To Cart Button
    4:20 - Add Javascript
    9:25 - Import Things In Views.py
    11:20 - Cart_Add View
    16:21 - Create Add Function To Cart
    18:50 - Troubleshoot
    20:14 - Test It Out
    20:42 - Check Session in Shell
    22:46 - Conclusion

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

  • @Codemycom
    @Codemycom  7 หลายเดือนก่อน +1

    ▶ Watch Django Wednesdays Ecommerce Playlist ✅ Subscribe To My TH-cam Channel:
    bit.ly/3OBQJfN 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 50% off with coupon code: youtube50 bit.ly/2VC9WUN
    ▶ Get The Code
    bit.ly/47xAhWJ

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

    Awesome series! can't wait to next wednesday!

    • @Codemycom
      @Codemycom  7 หลายเดือนก่อน +1

      glad you're enjoying it!

  • @JK-nx1wd
    @JK-nx1wd 3 หลายเดือนก่อน

    Thanks John, from here in the UK. A super tutorial again (just recently found you while trying to make sense of a 5 yr old eccomerce tutorial where all the requirements.txt files were out of date so got a bit lost ha .. a big learning curve in this session for sure but a good feeling when get a 200 server code. Think the JavaScript course is next on the cards! :)

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

      Glad you're enjoying it! Yeah this one was a bit tougher than usual!

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

    Whoa that was a bit to take in! I literally know nothing about JavaScript so may need to learn more about that, especially when I'm also trying to understand HTMX (not related to your course here) Great work as always John! Off to the next video as I'm a bit behind :D

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

      awesome

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

    great as always.

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

      Thanks!

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

    Hey John, In this tutorial you didn't use login decorators. Anyone can add product to cart and move to billing and payment without even registering. I hope you will address this small issue in upcoming video.
    You are doing great. Thank you.

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

      Just throw an:
      if request.user.is_authenticated and request.user.is_superuser:
      Into your view...no biggie.

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

    Good Morning
    Thank you, i had some issues with the concept of cookies and sessions
    Now i got
    Just finished #13
    Waiting for #14 next week

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

    Woow, congralutions for tutorial, my friend. I'm from Brazil and I follow you here on TH-cam
    When will the next video come out changing the view and cart?

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

      The series is called Django Wednesdays

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

    عالی👍امیدوارم موفق باشی😊ادامه بده

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

    Hi best one ever

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

      Thanks!

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

    Amazing

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

      thanks!

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

    💚💚💚💚

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

      🙂

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

    John in the admin panel, the admin can change password of ANY user through an option given "this form". can you please teach us how to remove this option for the admin? thanks

    • @Codemycom
      @Codemycom  7 หลายเดือนก่อน +1

      No, we want the admin to have that ability. That's what it means to be the Admin.

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

      alright thanks for clearing that up :) @@Codemycom

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

    Great tutorial John, thanks.
    By the way, anyone having error like this :
    "TypeError: argument of type 'NoneType' is not iterable" in line > if product_id in self.cart. any idea how to solved it?

    • @multizloy
      @multizloy 6 หลายเดือนก่อน +2

      I had this problem in ajax(product detail template). So i changed product_id: $('add_cart').val() line for this product_id : '{{ product.id}}'. Hope it will help.

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

      thanks man) you save me )@@multizloy

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

      @@multizloy this helped me! I had error ValueError: Field 'id' expected a number but got 'ID: 1'. in CMD. Change to what you provided and fixed it. Thanks!

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

    One thing i dont understand is that you are not relating the models (Product and cart in this case) to the user. So in theory with your code, all user would share the same Cart and Product objects!
    can you please tell me if this is correct?

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

      No, it's not correct.

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

    If I log out, it will be gone, right?
    What do people usually use for cart models or sessions?

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

      Yes, we'll build permanence later in the playlist.

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

    John pls am having error in adding to cart
    Saying can't convert my request from product Id to integer

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

      You have a typo in your code. Read thru the comments to see that others did too...and how to fix.

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

    Hey, at 20:15 when i click on the "add to cart" button i get this error in the terminal: ValueError: The view cart.views.cart_add didn't return an HttpResponse object. It returned None instead.
    I tried to solve this but i have no ideia what i did wrong. Can someone help me?

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

      You made a mistake in your code. Check it vs the video to see what.

    • @ryanv0910
      @ryanv0910 4 หลายเดือนก่อน +1

      @@CodemycomI found the problem, I had written something wrong

  • @Minimal_programming
    @Minimal_programming 8 วันที่ผ่านมา +1

    I have a problem bro ... I don't get any errors and concole doesn't show anything either this code

    • @Codemycom
      @Codemycom  8 วันที่ผ่านมา +1

      What's the problem then?

    • @Minimal_programming
      @Minimal_programming 4 วันที่ผ่านมา

      Error is : jquery-3.7.1.min.js:2
      POST 127.0.0.1:8000/product/%7B%%20url%20'cart_add'%20%%7D 404 (Not Found)

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

    In my product.html, I am seeing a error within the JavaScript code on line "url: '{% url 'cart_add' %}',". However, when I run the code on the browser, I am getting a 200 status when clicking on the Add to cart button and the product shows up in the session id within python shell on the terminal. Should I be concerned? I am using VScode as my code editor.

    • @haitambainy5571
      @haitambainy5571 หลายเดือนก่อน +1

      i have the same probleme

    • @Codemycom
      @Codemycom  หลายเดือนก่อน +1

      You're getting errors and asking if you should be concerned? Of course you should be concerned...you have an error in your code that needs to be fixed. I can't guess what it is...put it aside for a few days to clear your mind, then compare it to the video code to see what you did differently.

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

      @@haitambainy5571 I put up my problem into stack overflow and got it fixed. If you are using vscode as well, you would just need to install a Django extension into vscode. I typed in Django into the search bar and installed the first one by Baptiste Darthenay. What happened for me is that the JavaScript was correct, as shown by John Elder, but vscode didn't understand it and made the line of code into an error. I was recommended to install a Django or Django template extension. Hope this helps

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

      Hi, I'm also using VScode and getting the same "error". I'm pretty sure this just shows because it's django code where it should be javascript and the editor shits itself. So far i've had no actual issues besides the red line underneath

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

      @@americahater2 no clue, I'd never use vscode for python

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

    And is there a way to use only python language without using jquery cause some of us don't have knowledge on it

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

      no. But I teach you everything you need in this video, so you do have the knowledge you need.

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

    What if I want to install jQuery in my virtual environment, what do I do

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

      Add it to a js directory in a static directory and call it using the regular static django method

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

    Can I just use fetch instead of jQuery

    • @Codemycom
      @Codemycom  7 หลายเดือนก่อน +1

      If you have to ask, then probably no

  • @BlackCodeDev
    @BlackCodeDev 2 หลายเดือนก่อน +1

    I am get an error just in this video add/ 500 xhr

    • @Codemycom
      @Codemycom  2 หลายเดือนก่อน +1

      what's the exact error?

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

      @@Codemycom thank you I just got resolved with your GitHub thank you very much I watched a lot of videos but your course is special to me you have different way to teach anyone thank you very much

  • @allandekengni6745
    @allandekengni6745 20 วันที่ผ่านมา

    Great tutorial
    By the way, anyone having error like this : TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType' ? pls need help

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

      you just have a typo somewhere...compare your code to the video to discover it

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

    I was trying to do a pricing section on my website using this, however I faced an issue where no matter what button I clicked for my pricing package. it was always the same ID and name being retrieved, I fixed that with var product_id = $(this).val(); in the script
    If anyone was facing the same issue ..
    Thank you for the series. Looking forward for more. You are awesome!

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

      Nice, glad you got it sorted out!

  • @romanbuchta248
    @romanbuchta248 7 หลายเดือนก่อน +2

    O.K. From this point it's a little bit voodoo .... 😧 - but I keep going on ....

    • @Codemycom
      @Codemycom  7 หลายเดือนก่อน +1

      ha

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

      agree!

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

    where is you'r github link

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

      In the pinned comment, like I said in the video.

  • @user-hm3du1yp1j
    @user-hm3du1yp1j 3 หลายเดือนก่อน

    I got this error
    "The view cart.views.cart_add didn't return an HttpResponse object. It returned None instead."
    can you help?

    • @ketilkn
      @ketilkn 3 หลายเดือนก่อน +1

      You either forgot to return anything from your cart_add function, or you do not return a JsonResponse there, or your return is missaligned causing it to belong to an unexpected block.

    • @user-hm3du1yp1j
      @user-hm3du1yp1j 3 หลายเดือนก่อน +1

      thank you@@ketilkn

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

      @@user-hm3du1yp1j What was the mistake?

    • @user-hm3du1yp1j
      @user-hm3du1yp1j 3 หลายเดือนก่อน +1

      @@ketilknit was actually in my ajax, it was error when i write like this '{% url 'cart_add' %}', but when i changed it to "{% url 'cart_add' %}" it works

    • @JK-nx1wd
      @JK-nx1wd 3 หลายเดือนก่อน

      @@user-hm3du1yp1j thanks - i had the ' parenthesis instead of " too - spotted everything up to this point but that session was one steep learning curve haha

  • @user-lc4vc2oq7l
    @user-lc4vc2oq7l 5 หลายเดือนก่อน +1

    Error during template rendering
    In template C:\Users\d\django\ecom\store\templates\product.html, error at line 75
    'cart' is not a registered namespace
    65
    66
    67
    68
    69
    70 // Check if button pressed
    71 $(document).on('click', '#add-cart', function(e){
    72 e.preventDefault();
    73 $.ajax({
    74 type: 'POST',
    75 url: '{% url 'cart:cart_add' %}',
    76 data: {
    77 product_id: $('#add-cart').val(),
    78 product_qty: $('#qty-cart option:selected').text(),
    79 csrfmiddlewaretoken: '{{ csrf_token }}',
    80 action: 'post'
    81 },

    • @Codemycom
      @Codemycom  5 หลายเดือนก่อน +1

      line 75 should be: url: '{% url 'cart_add' %}',
      not cart:cart_add

    • @user-lc4vc2oq7l
      @user-lc4vc2oq7l 5 หลายเดือนก่อน

      i dont know how but i keep getting the same error. it seems the html tags cant read from the cart app@@Codemycom