Tornado static files serving url configuration

2019-08-04 00:24发布

问题:

I configured torando for serving static files for development purposes.

            settings = {
                    'template_path': 'templates',
                    'static_path': 'static'
            }

Inside my template files I am using static_url() to give proper path to my static files.

Because my html files have structure of static files already defined tornado static_url isn't showing correct path.

For example, on my server file is having url like

<link href="/myflz/resources/css/bootstrap.css" rel="stylesheet"/>

and after using static_url it is

<link href="/static/myflz/resources/css/bootstrap.css" rel="stylesheet"/>

How can I get rid of static before myflz because changing 'static_path': 'static' to 'static_path': 'myflz' doesn't work, it still uses static in front.

回答1:

You want static_url_prefix (which replaces /static/ at the front of the url) instead of static_path (which is the location on disk where the static files are stored).