V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
Stitch
V2EX  ›  Python

Flask 内网 nginx+gunicorn+virtualenv 部署 bootstrap( js/css)文件加载问题

  •  
  •   Stitch · 2016-06-20 19:26:00 +08:00 · 3651 次点击
    这是一个创建于 2877 天前的主题,其中的信息可能已经有所发展或是发生改变。

    使用 nginx+gunicorn+virtual 部署 flask 应用,因为是公司内网,故需要的 js 和 css 想从本地加载。

    1. 、在配置了 flask_bootstrap 的__init__.py 的 app.config.setdefault('BOOTSTRAP_SERVE_LOCAL', True)后

      经过验证, js 和 css 是从本地加载的。

      路径为: http://IP:8080/static/bootstrap/js/bootstrap.min.js?bootstrap=3.3.5.7

    2. 、为了提升性能,静态文件使用 nginx 代理,配置了静态文件加载路径

    location ~ ^/static/.*$ { root /myflask/app; }
    发现 nginx 直接从 /myflask/app/static/下取 js 和 css ,无法加载到静态文件。 但是实际的 bootstrap 文件是经过 wsgi 计算得到的,
    实际文件夹下不存在这个文件。
    如果放置文件,则需要在 html 模板中手动的添加 js 和 css 文件。

    请教高手们,你们是怎么解决这个问题的,多谢

    2 条回复    2016-06-21 12:07:18 +08:00
    Stitch
        2
    Stitch  
    OP
       2016-06-21 12:07:18 +08:00
    @187j3x1 非常感谢,
    设置了 BOOTSTRAP_QUERYSTRING_REVVING 这个遍历后,不再请求 js 的版本号。

    同时在 static 文件下放置 js 和 css 文件即可。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5503 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 07:11 · PVG 15:11 · LAX 00:11 · JFK 03:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.