1

我正在使用flask 和flask_bootstrap 制作应用程序。

我从这个网站中选择了一个主题。您可以在线编辑该主题的变量以对其进行自定义。最后,您可以将编辑结果下载bootstrap.css到本地。

现在我必须将这个 bootstrap.css 复制并粘贴到venv/lib/python3.4/site-packages/flask_bootstrap/static/css并覆盖原来的那个。只有这样,我才能让我的网站在错误消息中正常工作。但是每次升级flask_bootstrapin pip虚拟环境时,我都必须再次复制和粘贴css文件。我觉得这很无聊,我相信应该有一个解决方案。

我尝试将自定义站点生成bootstrap.css的放在我自己的static文件夹中并添加<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='theme_page.css') }}" />参考。但是会弹出一批错误消息,例如:"GET /fonts/glyphicons-halflings-regular.woff2 HTTP/1.1" 404 -. 我知道这是因为在自定义的 css 文件中,有对字体文件夹的引用,但显然我自己的static文件夹不是位于venv.../flask_bootstrap/static并真正包含的文件夹/fonts

那么有什么好的建议吗?谢谢!

4

1 回答 1

1

我所做的是

  • 从 custom 中取出包含对外部文件(所以字体)的引用的行bootstrap.css,和
  • 将它们包含在我的基本模板中{% block styles %}
<style>
    @font-face {
    font-family: 'Glyphicons Halflings';
        src: url('{{ url_for("bootstrap.static", filename="fonts/glyphicons-halflings-regular.eot") }}');
        src: url('{{ url_for("bootstrap.static", filename="fonts/glyphicons-halflings-regular.eot?#iefix") }}') format('embedded-opentype'), 
             url('{{ url_for("bootstrap.static", filename="fonts/glyphicons-halflings-regular.woff2") }}') format('woff2'), 
             url('{{ url_for("bootstrap.static", filename="fonts/glyphicons-halflings-regular.woff") }}') format('woff'), 
             url('{{ url_for("bootstrap.static", filename="fonts/glyphicons-halflings-regular.ttf") }}') format('truetype'), 
             url('{{ url_for("bootstrap.static", filename="fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular") }}') format('svg');
    }
</style>

这将在原始位置查找可以升级的字体。

或者您可以将它们放在模板中并使用以下内容:

<style>
    {% include "_bootstrap_fonts.css" %}
</style>
于 2018-06-23T12:14:21.657 回答