推荐学习书目
› 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
pc10201
V2EX  ›  Python

flask 中的全局变量设置问题?

  •  
  •   pc10201 · Mar 20, 2014 · 8093 views
    This topic created in 4579 days ago, the information mentioned may be changed or developed.
    现在有一个小应用,客户搜索一个词发出一个post请求,等页面加载完成之后立即通过ajax发出第二个请求

    第二个请求会用到第一个请求中的部分值
    虽然现在可以通过global这种方式设置全局变量,或者在第二个请求中再查询一下数据库,或者用jquery取得网页中的一些值,但感觉很不方便啊

    flask中的g对象和上下文是否能解决此问题?如何做到?
    2 replies  •  1970-01-01 08:00:00 +08:00
    likexian
        1
    likexian  
       Mar 20, 2014
    明显不能,因为第二个请求是页面加载完再请求的,g和上下文都取不到东西了
    cookies session什么的才适合
    ctsed
        2
    ctsed  
       Mar 20, 2014
    存在客户端啊,js变量或者cookie
    服务端试试 flash()或者返回的url加参数
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2245 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 10:57 · PVG 18:57 · LAX 03:57 · JFK 06:57
    ♥ Do have faith in what you're doing.