本文介绍了Tornado 静态文件服务 url 配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我配置了 torando 以提供用于开发目的的静态文件.

I configured torando for serving static files for development purposes.

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

在我的模板文件中,我使用 static_url() 为我的静态文件提供正确的路径.

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

因为我的 html 文件已经定义了静态文件的结构,tornado static_url 没有显示正确的路径.

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

例如,在我的服务器文件上有类似的 url

For example, on my server file is having url like

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

在使用 static_url 之后是

and after using static_url it is

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

我怎样才能在 myflz 之前摆脱静态,因为将 'static_path': 'static' 更改为 'static_path': 'myflz' 不起作用,它仍然在前面使用静态.

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.

推荐答案

您需要 static_url_prefix(替换 url 前面的 /static/)而不是 static_path(这是存储静态文件的磁盘位置).

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).

这篇关于Tornado 静态文件服务 url 配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:20