Setting a cookie in Django Rest Framework API <p>I am trying to set a cookie on my website when a GET request is made to an API end-point.</p> <p>In my <strong>urls.py</strong>, I have this:</p> <pre><code>url(r'^api/cookies/$', views.cookies, name='cookies'), </code></pre> <p>which points to this <strong>view</strong>:</p> <pre><code>@api_view(['GET']) def cookies(request): if request.method == 'GET': response = HttpResponse('Setting a cookie') response.set_cookie('cookie', 'MY COOKIE VALUE') if 'cookie' in request.COOKIES: value = request.COOKIES['cookie'] return Response('WORKS') else: return Response('DOES NOT WORK') </code></pre> <p>In other words, when this view is loaded through a GET method, I am setting a cookie. If the cookie is set properly, I return 'WORKS', otherwise, I return 'DOES NOT WORK'. </p> <p>Now, I am sending a GET request to this URL, and I get 'DOES NOT WORK', which means the cookie is not set properly. What am I doing wrong? How can I fix this? Note: I am using Django Rest Framework for my views.</p>