ERROR

93 views
Skip to first unread message

traore arouna

unread,
Aug 8, 2020, 4:21:14 PM8/8/20
to Django users
Hello
I am here because I am developing an e-commerce application.
But at a certain level of my code when I run my server with the command
python manage runserver
I have an error message
Uncaught ReferenceError: info is not defined
ERROR.PNG

Agoua David

unread,
Aug 8, 2020, 4:25:10 PM8/8/20
to django...@googlegroups.com
Can you send a screenshot of the view file

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2fdbf0c6-5f2e-4120-a524-6f3171c50389o%40googlegroups.com.

Kovy Jacob

unread,
Aug 8, 2020, 10:30:36 PM8/8/20
to django...@googlegroups.com
Are you switching into your projects directory and then using 'python manage.py runserver' from command prompt/terminal to run your website?

Yemin Sajid

unread,
Aug 9, 2020, 10:51:03 AM8/9/20
to django...@googlegroups.com
I think the error is from the frontend javascript code. Can u share snippets of that code?

Julio Cojom

unread,
Aug 9, 2020, 6:52:29 PM8/9/20
to django...@googlegroups.com
It is js error, show the script part. It seems like you referenced a variable before declare it. 

traore arouna

unread,
Aug 13, 2020, 4:56:38 PM8/13/20
to django...@googlegroups.com
ERROR ADDING CART.PNG
cartjs_file3.PNG
cartjs_file1.PNG
cartjs_file2.PNG

traore arouna

unread,
Aug 13, 2020, 4:57:26 PM8/13/20
to django...@googlegroups.com
and my view content




from django.shortcuts import render
from django.http import JsonResponse
import json
from .models import *



def store(request):
if request.user.is_authenticated:
customer = request.user.customer
order, created = Order.objects.get_or_create(customer=customer, complete=False)
items = order.orderitem_set.all()
cartItems = order.get_cart_items
else:
items = []
order = {'get_cart_total': 0, 'get_cart_items': 0, 'shipping': False}
cartItems = order['get_cart_items']

products = Product.objects.all()
context = {'products': products, 'cartItems': cartItems}
return render(request, 'store/store.html', context)


def cart(request):
if request.user.is_authenticated:
customer = request.user.customer
order, created = Order.objects.get_or_create(customer=customer, complete=False)
items = order.orderitem_set.all()
cartItems = order.get_cart_items
else:
items = []
order = {'get_cart_total': 0, 'get_cart_items': 0}
cartItems = order['get_cart_items']
context = {'items': items, 'order': order, 'cartItems': cartItems}
return render(request, 'store/cart.html', context)


def checkout(request):
if request.user.is_authenticated:
customer = request.user.customer
order, created = Order.objects.get_or_create(customer=customer, complete=False)
items = order.orderitem_set.all()
cartItems = order.get_cart_items
else:
items = []
order = {'get_cart_total': 0, 'get_cart_items': 0}
cartItems = order['get_cart_items']
context = {'items': items, 'order': order, 'cartItems': cartItems}
return render(request, 'store/checkout.html', context)

def updateItem(request):
data = json.loads(request.body)
productId = data['productId']
action = data['action']

print('action:', action)
print('productId:', productId)


customer = request.user.customer
product = Product.objects.get(id=productId)
order, created = Order.objects.get_or_create(customer=customer, complete=False)
orderItem, created = OrderItem.objects.get_or_create(order=order, product=product)

if action == 'add':
orderItem.quantity = (orderItem.quantity + 1)
elif action == 'remove':
orderItem.quantity = (orderItem.quantity - 1)

orderItem.save()

if orderItem.quantity <= 0:
orderItem.delete()


return JsonResponse('Item was added', safe=False)

Le sam. 8 août 2020 à 20:24, Agoua David <cdavi...@gmail.com> a écrit :

traore arouna

unread,
Aug 13, 2020, 5:04:32 PM8/13/20
to Django users
no I not switch to my web site
I alway in my local project directory

traore arouna

unread,
Aug 13, 2020, 5:07:12 PM8/13/20
to Django users
ok my js file is


var updateBtns = document.getElementsByClassName('update-cart')

for(var i = 0; i < updateBtns.length; i++)
{
updateBtns[i].addEventListener('click',function(){
var productId = this.dataset.product
var action = this.dataset.action
console.log('productId:',productId, 'action:',action )

console.log('USER:', user)
if(user === 'AnonymousUser')
{
console.log('Not logged in')
}
else
{
updateUserOrder(productId, action)
}

})
}

function updateUserOrder(productId, action){
console.log('User is logged in, sending data..')
var url = '/update_item/'
fetch(url, {
method:'POST',
headers:{
'Content-Type': 'application/json',
'X-CSRFToken': csrftoken,
},
body:JSON.stringify({'productId': productId , 'action': action})
})
.then((response) => {
return response.json()
})
.then((data) => {
console.log('Data:',data)
location.reload()
})
}

Akinfolarin Stephen

unread,
Aug 13, 2020, 5:24:37 PM8/13/20
to django...@googlegroups.com
your user variable is not define try to define it like is not referencing anything

traore arouna

unread,
Aug 13, 2020, 6:26:37 PM8/13/20
to Django users
where can define it

traore arouna

unread,
Aug 13, 2020, 6:31:29 PM8/13/20
to django...@googlegroups.com

Kasper Laudrup

unread,
Aug 14, 2020, 5:42:37 AM8/14/20
to django...@googlegroups.com
On 14/08/2020 00.29, traore arouna wrote:
> how define it
>

https://www.wikihow.com/Declare-a-Variable-in-Javascript

Akinfolarin Stephen

unread,
Aug 14, 2020, 5:50:17 AM8/14/20
to django...@googlegroups.com
can you send the code on github so i can help you debug properly

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

traore arouna

unread,
Aug 19, 2020, 1:34:56 PM8/19/20
to django...@googlegroups.com
ok no problem
i will do it

I had some problems with my computer, so it is ok now


traore arouna

unread,
Aug 19, 2020, 5:53:49 PM8/19/20
to Django users
Reply all
Reply to author
Forward
0 new messages