Django / Python: TypeError at / ‘NoneType’ object is not subscriptable

Tags: ,

Errors showing in at line data = cartData(request) and cartItems = cookieData['cartItems']

Errors showing exactly:

Exception Location:, line 55, in cartData, line 12, in store
    data = cartData(request), line 55, in cartData
cartItems = cookieData['cartItems']

from . utils import cookieCart, cartData
def store(request):
    data = cartData(request)
    cartItems = data['cartItems']
    order = data['order']
    items = data['items']

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

def cartData(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
    cookieData = cookieCart(request)
    cartItems = cookieData['cartItems']
    order = cookieData['order']
    items = cookieData['items']
    return {'cartItems': cartItems, 'order': order, 'items': items}


Your return statement in cartData() function should not be inside the else block. It should be in level same as your if else.

Source: stackoverflow