setup cherrypy as web server for django

347 views
Skip to first unread message

hjebbers

unread,
May 13, 2009, 2:12:55 PM5/13/09
to cherrypy-users
Greetings,

I'm building a web application for use in LAN (low traffic).
I want to use cherrypy as a webserver: I want cherrypy to serve the
static files; other requests should be passed to django.
I have a setup; cherrypy does serve the static files.
problem is that django still recieves the requests for the static
files.

what am I doing wrong?

def start():
import cherrypy
from django.core.handlers.wsgi import WSGIHandler
app = WSGIHandler()
cherrypy.config.update({'log.screen': True,'tools.wsgiapp.on':
True,'tools.wsgiapp.app': app})
conf = {'/static': {'tools.staticdir.on':
True,'tools.staticdir.dir': '/somewhere/static'},
'/media': {'tools.staticdir.on':
True,'tools.staticdir.dir': '/somewhere/media'}}
cherrypy.tree.mount(app, '/', config=conf)
cherrypy.server.quickstart()
cherrypy.engine.start()

kind regards,
henk-jan ebbers

Eric Larson

unread,
May 14, 2009, 12:59:52 PM5/14/09
to cherryp...@googlegroups.com
Hi,
You might want to consider just using the cherrypy wsgi server and do
something like this:

from paste.urlmap import URLMap
import static
import cherrypy

app = URLMap()
app['/'] = your_django_app
app['/static'] = static.Cling('path/to/static/files/')

cherrypy.tree.graft(app, '/')
cherrypy.quickstart()

I'm not saying this is the best way to do it as you have to use an
external static package which might not be as good as the cherrypy
staticdir tool. Hopefully someone else on the list will be able to
expand on your example to show the pros and cons of each approach
(*cough* fumanchu *cough* ;)

HTH,

Eric Larson


>
> >
>

hjebbers

unread,
May 15, 2009, 8:46:08 AM5/15/09
to cherrypy-users
I have it running using this, and this seems to work:

def start_server(options):
import cherrypy
from django.core.handlers.wsgi import WSGIHandler
app = WSGIHandler()
cherrypy.config.update({'global': {'log.screen': True}})
conf = {'/myappl': {'tools.wsgiapp.on': True,'tools.wsgiapp.app':
app},
'/static': {'tools.staticdir.on':
True,'tools.staticdir.dir': '/somewhere/static'},
'/media': {'tools.staticdir.on':
True,'tools.staticdir.dir': '/somewhere/media'}},

Eric Larson

unread,
May 15, 2009, 12:25:02 PM5/15/09
to cherryp...@googlegroups.com
So, it looks like when you mount the WSGI app at the root, then you
cannot mount a cherrypy app anywhere else on the tree (ie use the
staticdir tool).

Thanks for posting. Good to know!

Eric Larson

> >
>

hjeb...@gmail.com

unread,
May 15, 2009, 12:42:43 PM5/15/09
to cherryp...@googlegroups.com
yes it looks like it.
I am glad to have this running.
CherryPy is very stable and serves me very well for my purpose.

henk-jan ebbers

Eric Larson

unread,
May 17, 2009, 2:10:53 PM5/17/09
to cherryp...@googlegroups.com
Btw, on IRC I found out that the issue regarding mounting a WSGI app
at '/' and a cherrypy app at '/foo' is fine. The staticdir tool, on
the other hand, doesn't work in that scenario.

Eric Larson

hjeb...@gmail.com

unread,
May 17, 2009, 2:48:09 PM5/17/09
to cherryp...@googlegroups.com
yes.
one could use the django static serving, but they say:

class AdminMediaHandler(object):
"""
WSGI middleware that intercepts calls to the admin media directory, as
defined by the ADMIN_MEDIA_PREFIX setting, and serves those images.
Use this ONLY LOCALLY, for development! This hasn't been tested for
security and is not super efficient.
"""

other solutions I found for using django with cherrypy use 'AdminMediaHandler'.
Seems not the way to go.
Reply all
Reply to author
Forward
0 new messages