[Answer]-Why variable is `None` in my case?

1👍

Because you’re setting it on the response, and reading it back from the request. The version in request won’t be updated until the response has been sent to the client and the next request has been received.

0👍

You have to send response first like Daniel have suggested, you are setting cookie on response and then you have to return it. So that from that time, whenever a request will come it will be holding that cookie and you can access it. you can create function like this:

def cookie_setter(request):
    '''Do your function task and create response object
    '''
    if not 'last_user_visit' in request.COOKIES:
        response.set_cookie('last_user_visit', now)
    return response

Leave a comment