▶ 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
thank you for great tut. but when I click on a product that before added to cart it isn't add the quantity just I should change it from cart summary. how I can do that.
Hello sir, if we instead did it service_qty: $('#select'+ serviceid).val(), would it bring an error later on? Because with service_qty: $('#select'+ serviceid+ 'option:selected').text(), it is not working for me Thank you in advance, loving this series!
No. Code doesn't work for some people and not for you. If the code isn't working, you've done something wrong. Retrace your steps and figure out what that is...in this case, I think you left off a space before ' option:selected')
I got same error below but I found a typeerror like : product_id: $('this').data('index'),...and I correct it : product_id: $(this).data('index'), This works. Guess I was fooling myself XD btw thank you John for doing this tutorial, now I can keep moving forward 👍
Hi, really cool videos! I noticed that if I try to add something to the cart, logout, and after that try to log in again to the same user, I got an empty cart.
When i clicked in the quantity drop button, select the value to update and update. My dict update, and everything works, but the value in my quantity label, doesnt. Sorry if i have any mistake in my english.
Hi help please I have copied every code from your git hub page: I am receiving a sever internal error (500) at this address 127.0.0.1:8000/cart/update/ When I try to press the update button // Update Cart $(document).on('click', '.update-cart', function(e){ e.preventDefault(); // grab the product id var productid = $(this).data('index'); $.ajax({ type: 'POST', url: '{% url 'cart_update' %}', data: { product_id: $(this).data('index'), product_qty: $('#select' + productid + ' option:selected').text(), csrfmiddlewaretoken: '{{ csrf_token }}', action: 'post' }, success: function(json){ //console.log(json) //document.getElementById("cart_quantity").textContent = json.qty location.reload(); }, error: function(xhr, errmsg, err){ } }); })
@@CodemycomI’m determined to get it to work. I did type it all including the space but still got the error, copy pasting was a desperate move 😢. I will delete and retype
Update button doesn't work... I've tried to change int for str and vice versa... I also went for the video many times and I get the same error: product_id = int(request.POST.get('product_id')) TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType' "POST /cart/update/ HTTP/1.1" 500 64883
@@Codemycom Wow, this pre-saved me a few hours of troubleshooting. I was getting the error ValueError: invalid literal for int() with base 10: '' But the space before ' option:selected' helped a bunch
File "C:\Users\wwwak\OneDrive\Desktop\ecom\ecom\cart\views.py", line 46, in cart_update product_qty=int(request.POST.get('product_qty')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: ' ' plx provide valuable solution
product_qty = int(request.POST.get('product_qty')) ValueError: invalid literal for int() with base 10: '' Same error here like a user has written befor ..
@@Codemycom I have found the solution! There must be s space befor option:selected -> '#select' + productid + ' option:selected' in /cart_summary.html. It was easy for making this type-error. See you next week!!
product_qty = int(request.POST.get('product_qty')) ValueError: invalid literal for int() with base 10: ' ' The same error. I checked everything. I applied what was written in the comments and still this same error. And git doesn't work for now.... As I see I get the qte to be an empty string or a space. Some hints maybe?
@@Codemycom I checked the spelling and the space is there. I had previously an error in the java script code where it did not want to access the url and i needed to make a variable with the url and call it in the ajax function. Now, in the cart.py file we have the cart add function where we cat from our cart the id and qte. I discovered that the syntax product_id = str(product.id) was something wrong. I deleted the .id from the syntax and at first glance it works. The code was the same as in your tutorial and double checked with github repo. Maybe i have something wrong or misspelled somewhere else... I modified the qte several times, i checked the page and it gets correct the product id. I wil dig more in to it to see if i made something wrong on the way. Thanks. By the way great tutorial sir.
def cart_upd(request): cart = Cart(request) if request.POST.get('action') == 'post': product_id = int(request.POST.get('product_id')) product_qty = int(request.POST.get('product_qty')) cart.update(product=product_id, quantity=product_qty) response = JsonResponse({'qty':product_qty}) return response line 30, in cart_upd product_qty = int(request.POST.get('product_qty')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: '' Any idea what could be the problem? I've watched the video three times, and I believe I've copied everything correctly
Probably an error on your cart_summary.html page. The product_qty you are passing can't be turned into an int. There must be s space before option:selected -> '#select' + productid + ' option:selected' in /cart_summary.html
▶ 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
that little space between ' option:selected' got me thinking for an good 10 minutes hahahaha good series, enjoying it a lot
Ha
fortunately i read this comment. i try this tutorial in a whole day for the update button to work and find out just got messed by a single space 🥲🤣
@@cyanokid4895 I had this error ahhahhaha for about 1 hour
Thank you for your very descriptive and understandable videos John! 😀
Glad you're enjoying them!
thank you for great tut. but when I click on a product that before added to cart it isn't add the quantity just I should change it from cart summary. how I can do that.
you typed something wrong in your code
Is the same procedure for the delete button, because I can try do it by myself :D
I also add pagination, contact form and update footer.
Pretty much, slightly different...we'll do that next week.
@@Codemycom Thanks, can't wait
Hello sir, if we instead did it service_qty: $('#select'+ serviceid).val(), would it bring an error later on? Because with service_qty: $('#select'+ serviceid+ 'option:selected').text(), it is not working for me
Thank you in advance, loving this series!
No. Code doesn't work for some people and not for you. If the code isn't working, you've done something wrong. Retrace your steps and figure out what that is...in this case, I think you left off a space before ' option:selected')
I got same error below but I found a typeerror like : product_id: $('this').data('index'),...and I correct it : product_id: $(this).data('index'), This works. Guess I was fooling myself XD
btw thank you John for doing this tutorial, now I can keep moving forward 👍
Glad to hear it!
Hi, really cool videos! I noticed that if I try to add something to the cart, logout, and after that try to log in again to the same user, I got an empty cart.
Is it only my mistake or this bug that have to be fixed?
We haven't addressed this yet in the playlist, we only just added the ability to register.
💙💙💙💚💚💚
🙂
When i clicked in the quantity drop button, select the value to update and update. My dict update, and everything works, but the value in my quantity label, doesnt. Sorry if i have any mistake in my english.
What did you do differently from the video?
I dont know, but after the problem,i copied view, cart_update and html. And not working yet@@Codemycom
$(document).on('click', '.update-cart', function (e) {
e.preventDefault();
// grab the product id
var productid = $(this).data('index');
$.ajax({
type: 'POST',
url: '{% url "cart:cart_update" %}',
data: {
product_id: $(this).data('index'),
product_qty: $('#select' + productid + ' option:selected').text(),
csrfmiddlewaretoken: '{{ csrf_token }}',
action: 'post'
},
success: function (json) {
//console.log(json)
//document.getElementById("cart_quantity").textContent = json.qty
location.reload();
},
error: function (xhr, errmsg, err) {
}
});
})
Quantity:
{% for key, value in quantities.items %}
{% if key == product.id|slugify %}
{{ value }}
{% endif %}
{% endfor %}
1
2
3
4
5
@@Codemycom
I think the problem is in my html, because the session id update the quantity, but i can find it.. @@Codemycom
Hi help please I have copied every code from your git hub page: I am receiving a sever internal error (500) at this address 127.0.0.1:8000/cart/update/
When I try to press the update button
// Update Cart
$(document).on('click', '.update-cart', function(e){
e.preventDefault();
// grab the product id
var productid = $(this).data('index');
$.ajax({
type: 'POST',
url: '{% url 'cart_update' %}',
data: {
product_id: $(this).data('index'),
product_qty: $('#select' + productid + ' option:selected').text(),
csrfmiddlewaretoken: '{{ csrf_token }}',
action: 'post'
},
success: function(json){
//console.log(json)
//document.getElementById("cart_quantity").textContent = json.qty
location.reload();
},
error: function(xhr, errmsg, err){
}
});
})
I never recommend copying and pasting code. Follow the video and write it out yourself.
@@CodemycomI’m determined to get it to work. I did type it all including the space but still got the error, copy pasting was a desperate move 😢. I will delete and retype
TypeError at /cart/update/
int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
What did you do differently from the video?
Update button doesn't work...
I've tried to change int for str and vice versa...
I also went for the video many times and I get the same error:
product_id = int(request.POST.get('product_id'))
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
"POST /cart/update/ HTTP/1.1" 500 64883
There's likely a problem with your javascript code on the cart-summary.html page or the button HTML code itself.
There must be s space befor option:selected -> '#select' + productid + ' option:selected' in /cart_summary.html
@@Codemycom Wow, this pre-saved me a few hours of troubleshooting. I was getting the error
ValueError: invalid literal for int() with base 10: ''
But the space before ' option:selected' helped a bunch
@@Codemycom Typo... There was a typo in my button HTML code:
I typed date-index instead of data-index.
Thanks
I made a few mistakes in spelling quantity as quanitity between cart.py and view.py first time around. The console/terminal gives you clues :)
File "C:\Users\wwwak\OneDrive\Desktop\ecom\ecom\cart\views.py", line 46, in cart_update
product_qty=int(request.POST.get('product_qty'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ' '
plx provide valuable solution
You have an error in your code...the comment section will show your solution.
product_qty = int(request.POST.get('product_qty'))
ValueError: invalid literal for int() with base 10: ''
Same error here like a user has written befor ..
Same answer then :-p
@@Codemycom I have found the solution! There must be s space befor option:selected -> '#select' + productid + ' option:selected' in /cart_summary.html. It was easy for making this type-error.
See you next week!!
product_qty = int(request.POST.get('product_qty'))
ValueError: invalid literal for int() with base 10: ' '
The same error. I checked everything. I applied what was written in the comments and still this same error. And git doesn't work for now.... As I see I get the qte to be an empty string or a space. Some hints maybe?
you missed a space in the ajax. There must be s space befor option:selected -> '#select' + productid + ' option:selected' in /cart_summary.html
@@Codemycom I checked the spelling and the space is there. I had previously an error in the java script code where it did not want to access the url and i needed to make a variable with the url and call it in the ajax function. Now, in the cart.py file we have the cart add function where we cat from our cart the id and qte. I discovered that the syntax product_id = str(product.id) was something wrong. I deleted the .id from the syntax and at first glance it works. The code was the same as in your tutorial and double checked with github repo. Maybe i have something wrong or misspelled somewhere else... I modified the qte several times, i checked the page and it gets correct the product id. I wil dig more in to it to see if i made something wrong on the way. Thanks. By the way great tutorial sir.
@@Codemycom but it doesn’t working ether, i put a space and checked my code several times
The inspect/console says - Failed to load resource: the server responded with a status of 500(internal server error )😢
@@AKHILjoseph01 I have the same did you get it fixed??
def cart_upd(request):
cart = Cart(request)
if request.POST.get('action') == 'post':
product_id = int(request.POST.get('product_id'))
product_qty = int(request.POST.get('product_qty'))
cart.update(product=product_id, quantity=product_qty)
response = JsonResponse({'qty':product_qty})
return response
line 30, in cart_upd
product_qty = int(request.POST.get('product_qty'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''
Any idea what could be the problem? I've watched the video three times, and I believe I've copied everything correctly
Probably an error on your cart_summary.html page. The product_qty you are passing can't be turned into an int.
There must be s space before option:selected -> '#select' + productid + ' option:selected' in /cart_summary.html
@@Codemycom
{% for key, value in quantities.items %}
{% if key == product.id|slugify %}
{{ value }}
{% endif %}
{% endfor %}
1
2
3
4
5
update
{% endfor %}
{% else %}
No hay productos agregados...
{% endif %}
$(document).on('click', '.update-cart', function(e){
e.preventDefault();
var productid = $(this).data('index');
$.ajax({
type: 'POST',
url: "{% url 'cart_update' %}",
data: {
product_id: $(this).data('index'),
product_qty: $('#select' + productid + 'option:selected').text(),
csrfmiddlewaretoken: '{{ csrf_token }}',
action: 'post'
},
success: function(json){
location.reload();
},
error: function(xhr, errmsg, err){
}
});
})
{% endblock %}
Literal, I copied everything exactly as it is.
This fix the problem
var productid = $(this).data('index');
//fix
var qty = $('#select' + productid + ' option:selected').text();
$.ajax({
type: 'POST',
url: "{% url 'cart_update' %}",
data: {
product_id: $(this).data('index'),
product_qty: qty,
csrfmiddlewaretoken: '{{ csrf_token }}',
action: 'post'
},
Can you explain to me why the other code isn't working?
Same error here .....
I have found the solution! There must be s space befor option:selected -> '#select' + productid + ' option:selected' in /cart_summary.html
@@romanbuchta248 ah yeah, correcto!