Flask,CherryPy和静态内容 [英] Flask, CherryPy and static content

查看:268
本文介绍了Flask,CherryPy和静态内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多关于 Flask CherryPy 和静态文件,但我仍然似乎无法让这个工作。



有一个代码段来部署Flask应用程序在CherryPy这里:
http://flask.pocoo.org/snippets/24/



有没有快速修改,让wsgiserver在烧瓶应用程序的静态目录中提供内容?


$ b $樱桃酱的静态内容功能似乎居于CherryPy中。而且我不确定如何安装一个CherryPy应用程序,但是在使用此代码段时不需要静态内容。

解决方案

是一个应该做你所要求的片段。这是基于这里提供的一组说明(这绝对值得一读,但我不知道最新的是如何)。

  import cherrypy 
from hello import app

cherrypy.tree.graft(app,'/')
cherrypy.tree.mount(无,'/ static',{'/':{
'tools.staticdir .dir':app.static_folder,
'tools.staticdir.on':True,
}}
cherrypy.config.update({
'server.socket_port' 8080,
})
cherrypy.engine.start()
cherrypy.engine.block()


I know there are plenty of questions about Flask and CherryPy and static files but I still can't seem to get this working.

There's a snippet to deploy a Flask app on CherryPy here: http://flask.pocoo.org/snippets/24/

Is there a quick modification to have the wsgiserver serve the content in the static directory of the flask app?

The static content features of CherryPy seem to reside within CherryPy. And I am unsure on how to mount a CherryPy app that does nothing but serve static content while working with this snippet.

解决方案

Here is a snippet that should do what you are asking for. This is based on the set of instructions provided here (it's definitely worth a read, though I'm not sure how up to date it is).

import cherrypy
from hello import app

cherrypy.tree.graft(app, '/')
cherrypy.tree.mount(None, '/static', {'/' : {
    'tools.staticdir.dir': app.static_folder,
    'tools.staticdir.on': True,
    }})
cherrypy.config.update({
    'server.socket_port': 8080,
    })
cherrypy.engine.start()
cherrypy.engine.block()

这篇关于Flask,CherryPy和静态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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