社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  问与答

通用视图怎么设置cookie呢?

该用户已被注销---weibo • 10 年前 • 3062 次点击  
> class IndexView(generic.ListView):
>         template_name = 'bbs/index.html'
>         def get_context_data(self, **kwargs):
>                 context = super(IndexView, self).get_context_data(**kwargs)
>           self.response_class.set_cookie('cookiecity', value='上海')
>                 return context

这里面报错。看意思我知道是没有绑定,但是不知道怎么绑定?谢谢 unbound method set_cookie() must be called with TemplateResponse instance as first argument (got str instance instead)

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/878
 
3062 次点击  
文章 [ 1 ]  |  最新文章 10 年前
Py站长
Reply   •   1 楼
Py站长    10 年前

使用 session self.request.session['sort_on'] = col_nm

http://stackoverflow.com/questions/22937995/how-to-set-cookie-in-class-based-generic-view