V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
anxudong
V2EX  ›  Python

django views 中怎么设置 cookie 的同时返回 json 数据,有人知道吗?

  •  
  •   anxudong · Oct 2, 2019 · 3875 views
    This topic created in 2401 days ago, the information mentioned may be changed or developed.

    目前代码是这样的,想加上 cookie return HttpResponse(json.dumps(data), content_type="application/json")

    3 replies    2019-10-02 17:19:42 +08:00
    anxudong
        1
    anxudong  
    OP
       Oct 2, 2019
    resp = HttpResponse()
    resp.set_cookie 这样设置了的话,json 那就是不是要改,该怎么样改呢,请教一下
    n329291362
        2
    n329291362  
       Oct 2, 2019
    response = HttpResponse(json.dumps(data), content_type="application/json")
    response.set_cookie(xxx,xxx)
    return response
    anxudong
        3
    anxudong  
    OP
       Oct 2, 2019
    @n329291362
    resp = HttpResponse(content_type="application/json")
    resp.set_cookie
    resp.content = json.dumps(data)
    恩,我这样改了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5395 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 07:33 · PVG 15:33 · LAX 00:33 · JFK 03:33
    ♥ Do have faith in what you're doing.