8

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.

plaes
  • 31,788
  • 11
  • 91
  • 89
MKaras
  • 2,063
  • 2
  • 20
  • 35

1 Answers1

6

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()
linqq
  • 3,067
  • 2
  • 19
  • 17
  • 1
    I'll try it out tonight and if it works I'll set as answer. I've been googling for so long. Thanks! – MKaras Feb 22 '12 at 11:22