Skip to content
Advertisement

Is there a way to check if some value is IN request.session.name?

Can anybody clarify, please? I got a Cart object in request.session I want to check if request.session.cart CONTAINS item.id as a key from template

{% if game.id in request.session.cart %}

I know that game.id is FOR SURE in that cart object, but template doesn’t react on that. I HAVE a context processor added

UPDATE:

SETTINGS.PY

        'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
            'order.context_processors.cart',
        ],

Template and session data

game.id is seen on the picture (actual value is not seen but it is the same as in cart) and below there is cart content template and session dataenter code here

Advertisement

Answer

Okay, everybody whom it might concern. The problem was that I had game.id value of UUID. The value passed to cart was a string. They “looked” the same, but types were different. I used {{ game.id|slugify }} to convert UUID to string. That’s it

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement