New Users Unable to Use Website

22 views
Skip to first unread message

Lightning Bit

unread,
Sep 19, 2020, 11:19:32 PM9/19/20
to Django users
Encountering a lot of errors here. Here is the spill: 


THE CASE:
So, I have created the base site with an operational store. However, now I am trying to add new users. 

I completed about half of the "setting up user accounts" tutorial, however, now, whenever a new user logs in, he/she is unable to access any of the pages on the website.

THE CAUSE
In fact, an "Exception Type: RelatedObjectDoesNotExist" and "Exception Value: User has no customer" appears.. This is stopping the website from being operational for new users. 

In the traceback, I am shown the following from "views.py" - "data = cartData(request)". Then, I am shown the following form "utils.py" - "customer = request.user.customer". This seems to be what is causing the errors. 

Views.py 

def about(request):

    data= cartData(request)

    items=data['items']
    order=data['order']
    cartItems=data['cartItems']

    context = {'items':items, 'order':order, 'cartItems':cartItems}
    return render(request, 'store/about.html', context)



CartData from Utils.py


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
            else:
                        cookieData = cookieCart(request)
                        cartItems = cookieData['cartItems']
                        order = cookieData['order']
                        items = cookieData['items']

            return{'cartItems':cartItems, 'order':order, 'items':items}  


THE CONFUSION
However, the store will not operate if I get rid of the cartData(request). How can I reconfigure the "views.py" or "utils.py" to make the cartData(request) operational for both admin and customers w/o this error appearing? 

Thanks everyone, I hope that someone knows how to bypass this.

RANGA BHARATH JINKA

unread,
Sep 19, 2020, 11:32:01 PM9/19/20
to django...@googlegroups.com

--
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/6f1e5336-8ffe-4955-989e-ec166649de82n%40googlegroups.com.

King Niko

unread,
Sep 20, 2020, 11:38:50 AM9/20/20
to django...@googlegroups.com
This method works! Thank you!

RANGA BHARATH JINKA

unread,
Sep 20, 2020, 11:41:37 AM9/20/20
to django...@googlegroups.com
You are welcome 😀



--
Thanks and Regards

J. Ranga Bharath
cell: 9110334114
Reply all
Reply to author
Forward
0 new messages