Wednesday, September 2, 2020

Re: DJANGO ADMINISTRATION ERROR & TemplateDoesNotExist

I have not managed to get the Django log up and running, but this may help to get guidance on resolving the issue:

I have noticed that most of my bugs reside within utils.py under the "cart = {}" :

def cookieCart(request):
    #Create empty cart for now for non-logged in user
    try:
        cart = json.loads(request.COOKIES['cart'])
    except:
        cart = {}
        print('CART:', cart)

    items = []
    order = {'get_cart_total':0, 'get_cart_items':0, 'shipping':False}
    cartItems = order['get_cart_items']

    for i in cart:
        #We use try block to prevent items in cart that may have been removed from causing error
        try:
            cartItems += cart[i]['quantity']

            product = Product.objects.get(id=i)
            total = (product.price * cart[i]['quantity'])

            order['get_cart_total'] += total
            order['get_cart_items'] += cart[i]['quantity']

            item = {
                'id':product.id,
                'product':{'id':product.id,'name':product.name, 'price':product.price,
                'imageURL':product.imageURL}, 'quantity':cart[i]['quantity'],
                'digital':product.digital,'get_total':total,
                }
            items.append(item)

            if product.digital == False:
                order['shipping'] = True
        except:
            pass

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

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) #This is affected by the cookieCart function
                        cartItems = cookieData['cartItems']
                        order = cookieData['order']
                        items = cookieData['items']

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


Maybe this code is what is causing the 500 Server Error? Whenever I look at the logging in the Heroku logs, it shows the "cart = {}" from utils.py. How can I resolve this issue? Would you need to see any other pieces of code to fix this bug?
[11:30 AM]
I also implemented this into my "tests.py" which actually allowed the website to appear and be functional rather than having 500 Server Errors all throughout the website. This, somehow, fixed this 500 Server Errors on every page but the "Cart" and "Checkout". I can still "add" items to my cart and see the number increase on each page, but when I click the "Cart" I receive a 500 Server Error - the same occurs when I type in the url for the "Checkout" page. Here is the code in my "tests.py":

from django.test import TestCase, override_settings

# Create your tests here.
class MyTest(TestCase):
    @override_settings(STATICFILES_STORAGE='django.contrib.staticfiles.storage.StaticFilesStorage')
    def test_something(self):
        pass

On Tue, Sep 1, 2020 at 5:01 PM Kasper Laudrup <laudrup@stacktrace.dk> wrote:
Hi King Niko,

On 01/09/2020 07.43, King Niko wrote:
> The console does not seem to provide much information. It is simply
> stating that there is a 500 Server Error. I tried sifting for more
> details but there were none.
>

The console in your browser is not providing any information because it
doesn't make much sense to try and debug a *Server Error* on the client
side.

Ignore the advice from RANGA BHARATH JINKA on looking in your browsers
console.


> However, in the:
>
> *> heroku logs --tail *
> *
> *
> It simply mentions that none of the paths exist to /the cart / and /the
> images /that derive from the DJANGO ADMINISTRATION page.

That sounds a lot more useful, but are you really sure you're seeing the
logs from Django and not just the web server forwarding requests to your
Django application?

You need to get the logs from your actual Django application to see the
actual cause of the error. I remember there has been other discussions
on getting those logs from Heroku, but I have no experience with Heroku
so I don't know how to achieve that, but you need access to those logs
sooner or later so start by figuring out how to do that.

Kind regards,

Kasper Laudrup

--
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/299d7a71-faf2-71aa-fdfb-d5b53bc6127b%40stacktrace.dk.

--
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/CAO1EWpETNaqna%2BoO-MdDw-NnTD8cO5WyGJQmLyeM8CUZygnW%2BA%40mail.gmail.com.

No comments:

Post a Comment