views.py
# Get cookie
def favorite_color(request):
if 'favorite_color' in request.COOKIES:
favorite_color = request.COOKIES['favorite_color']
return HttpResponse('Your favorite color is %s' % favorite_color)
else:
return HttpResponse('You don\'t have a favorite color.')
# Set cookie
def set_color(request):
if 'favorite_color' in request.GET:
response = HttpResponse('Your favorite color is %s' % request.GET['favorite_color'])
response.set_cookie('favorite_color', request.GET['favorite_color'])
return response
else:
return HttpResponse('You don\'t have a favorite color.')
Комментариев нет:
Отправить комментарий