code: def set_cookie(response, key, value, max_age):
      
      expires = datetime.strftime(
          datetime.utcnow() + timedelta(seconds=max_age),
          "%a, %d-%b-%Y %H:%M:%S GMT"
      )
      response.set_cookie(
          key,
          value,
          max_age=max_age,
          expires=expires,
          domain=settings.SESSION_COOKIE_DOMAIN,
          secure=settings.SESSION_COOKIE_SECURE or None
      )
docs: Set the cookie ``key`` on ``response`` with value ``value`` valid for ``max_age`` secondes
  
          :param django.http.HttpResponse response: a django response where to set the cookie
          :param unicode key: the cookie key
          :param unicode value: the cookie value
          :param int max_age: the maximum validity age of the cookie