使用Django的会话框架应该涵盖大多数情况,但是Django现在也可以在请求和响应对象上提供直接的cookie操作方法(因此您不需要帮助函数)。设置Cookie:def view(request): response = HttpResponse('blah') response.set_cookie('cookie_name', 'cookie_value')检索Cookie:def view(request): value = request.COOKIES.get('cookie_name') if value is None: # Cookie is not set # OR try: value = request.COOKIES['cookie_name'] except KeyError: # Cookie is not set