Problem with Static Files Serving

Skip to first unread message

reza miri

Dec 13, 2022, 7:55:48 AM12/13/22
to cherrypy-users
Hello to those who see this,

I have a problem running two simple applications in Cherrypy where I want to:
  • mount Root() to handle static data in the "/" endpoint
  • mount NodeApi() to handle Json Rest requests using the default dispatcher in the "/api" endpoint
The code is as follows:

class Root(object):

class NodeApi(object):
        #some implemented functions accessible via @cherrypy.expose
'/': {
        'tools.sessions.on': True,
        'tools.staticdir.root': ".../project/static" ,
        'tools.staticdir.index': ".../project/static/index.html"
cherrypy.tree.mount(root=Root(), '/', config=ROOT_CONF)
cherrypy.tree.mount(root=NodeApi(), script_name='/api')

The cherrypy runner code ( is placed in the ".../project" directory. The problem is that I can succesfully send request at http://...../api/somefunction and recieve desired result in json format, but I can't accesss my static data such as:
  1. http://......./   --> return .../project/static/index.html
  2. http://......./   --> return .../project/static/index.html
  3. http://...../assets/main.js  --> return .../project/static/assets/main.js
  4. http://...../assets/icon.png  --> return .../project/static/assets/icon.png
Unbelivebly some "/assets/..." would be resolved and some don't, also non of the static files within the "/project/statics" would be resolve at the root endpoint.

Overall, I think that I haven't choose the right method to implement this, any help on my issue or alternative solution is appriciated.

Tnx in advance,

Sviatoslav Sydorenko (@webknjaz)

Jan 16, 2023, 12:04:12 PMJan 16
to cherrypy-users

вівторок, 13 грудня 2022 р. о 13:55:48 UTC+1 пише:
'/': {

I wouldn't mount both `Root()` and the static handler on `'/'`. Try using `'/assets/'` instead.

        'tools.staticdir.root': ".../project/static" ,

I believe you may have to use full absolute directory path for this.

        'tools.staticdir.index': ".../project/static/index.html"

I've just checked some of my snippets, and it seems this could be just `'index.html'`.
Reply all
Reply to author
0 new messages