Django是否支持多值Cookie? [英] Does Django support multi-value cookies?

查看:129
本文介绍了Django是否支持多值Cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过Django设置一个cookie,具有几个不同的值,类似于.NET的 HttpCookie.Values 属性。查看文档,我不知道这是否可行。看起来它只是一个字符串,所以有另一种方式?

I'd like to set a cookie via Django with that has several different values to it, similar to .NET's HttpCookie.Values property. Looking at the documentation, I can't tell if this is possible. It looks like it just takes a string, so is there another way?

我已经尝试传递一个数组( [10,20, 30] )和字典( {'name':'Scott','id':1} ),但他们只是被转换成他们的字符串格式。我目前的解决方案是使用任意的分隔符,然后在读取它时解析它,这感觉到icky。如果多值不可行,有没有更好的方法?我宁愿不要使用大量的cookies,因为这样会令人讨厌。

I've tried passing it an array ([10, 20, 30]) and dictionary ({'name': 'Scott', 'id': 1}) but they just get converted to their string format. My current solution is to just use an arbitrary separator and then parse it when reading it in, which feels icky. If multi-values aren't possible, is there a better way? I'd rather not use lots of cookies, because that would get annoying.

推荐答案

与使用分隔符的django中所做的一样。他们刚刚为你抽象出来。你在做什么是正确的,我不认为Django有什么具体的解决这个问题。

.NETs multi-value cookies work exactly the same way as what you're doing in django using a separator. They've just abstracted that away for you. What you're doing is fine and proper, and I don't think Django has anything specific to 'solve' this problem.

我会说你在做正确的事情,在不使用多个cookie。通过做你正在做的工作,保持线上开销。

I will say that you're doing the right thing, in not using multiple cookies. Keep the over-the-wire overhead down by doing what you're doing.

这篇关于Django是否支持多值Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆