Home  >  Q&A  >  body text

python - Flask 中 CSS 能否放在其他位置?

想要用 Flask 开发一个类似于 Hexo 的静态博客系统,可以本地跑 server 预览博客,最终生成 完整的 HTML 站点。支持更换主题。
文件结构如下:

/blog
    server.py
    generate.py
    /templates
        /theme1
            layout.html
        /theme2
            layout.html
    /static
        /theme1
            style.css
        /theme2
            style.css

比如在 theme1 的 layout.html 中连接 CSS 要这样做:

<link rel="stylesheet" type="text/css" href="static/theme1/style.css">

这样会给主题编写带来麻烦。有没有什么方法使得访问 CSS 更简单?最好是用简单一句 href="style.css" 就能够访问。(但是把 style.css 放在 theme1 文件夹里并没有用。)

PHP中文网PHP中文网2720 days ago490

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 17:18:47

    It’s best to be patient and read the docs provided by Flask

    static-files

    reply
    0
  • 黄舟

    黄舟2017-04-17 17:18:47

    Blueprint can configure static_folder, I don’t know if it can meet your needs.
    Link

    reply
    0
  • Cancelreply