M
M
Mooris2018-09-23 22:11:40
Django
Mooris, 2018-09-23 22:11:40

Django, what's wrong and how to get cookies?

Hello, tell me how to get cookies, I try like this

def test(request):
      t = request.COOKIES.get('test2')
      return t

Gives an error message
'SafeText' object has no attribute 'COOKIES'

site cookies:
5ba7e44e05f6c764815921.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mooris, 2018-09-24
@Mooris

@register.simple_tag(takes_context = True)
def tag_name(context):
    request = context['request']
    result = request.COOKIES.get('test2')
    return result

{% tag_name %}

R
Roman Kitaev, 2018-09-23
@deliro

Obviously, not Request, but some SafeText comes to your "view". By the way, it also returns not a valid Response, but a string or None

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question