Problems Serving Static Files in CherryPy 3.1

I'm having trouble creating a static XML stylesheet to accompany some dynamically generated output from a CherryPy web application. Even my test case serving a static text file fails.

The static file blah.txtis located in a directory /staticin the root directory of the application.

In my main site file (conesearch.py ​​contains the CherryPy ConeSearch page handler class):

import conesearch
cherrypy.config.update('site.config')
cherrypy.tree.mount(conesearch.ConeSearch(), "/ucac3", 'ucac3.config')
...

And in site.configI have the following options:

[/]
tools.staticdir.root: conesearch.current_dir

[/static]
tools.staticdir.on: True
tools.staticdir.dir: 'static'

where current_dir = os.path.dirname(os.path.abspath(__file__))inconesearch.py

However, my simple test page (taken directly from http://www.cherrypy.org/wiki/StaticContent ) fails 404:

def test(self):
        return """
        <html> 
        <head>
        <title>CherryPy static tutorial</title>
        </head>
        <body>
        <a href="/static/blah.txt">Link</a>
        </body>
        </html>"""
test.exposed = True

127.0.0.1:8080/static/blah.txt, AOK. ?

,

+3
3

cherrypy.config.update ( server.*), , ( tree.mount).

[/] [/static] site.config ucac3.config, .

+4

:

config = {'/static':
                {'tools.staticdir.on': True,
                 'tools.staticdir.dir': PATH_TO_STATIC_FILES,
                }
        }

cherrypy.tree.mount(MyApp(), '/', config=config)
+3

. , , http://mysite.com/site / /path//WWW.

server.cfg :

[global]
...
app.mount_point = '/site'
tools.staticdir.root = '/path/to/www/'
[/static]
tools.staticdir.on = True
tools.staticdir.dir = 'static'

I maintain dojo files, etc. from a static directory without problems, as well as css. I also use genshi for patterns and using the cherrypy.url () call to make sure my other URLs are set correctly. This allows me to modify app.mount_point and update my links.

+1
source

Source: https://habr.com/ru/post/1738109/


All Articles