Saturday, September 19, 2020

Re: New Users Unable to Use Website


On Sun, 20 Sep 2020, 8:50 am Lightning Bit, <thelegendofearthreturns@gmail.com> wrote:
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.

--
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+unsubscribe@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.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK5m316h3JpBpjWF1uWsentu47VnzDuYi0P2OXo_o2zwV8Qf2w%40mail.gmail.com.

No comments:

Post a Comment