Rumah  >  Soal Jawab  >  teks badan

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 hari yang lalu503

membalas semua(2)saya akan balas

  • 天蓬老师

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

    最好耐心的去看看Flask 给出的docs

    static-files

    balas
    0
  • 黄舟

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

    Blueprint 可以配置 static_folder, 不知道是否可以满足你的需求。
    链接

    balas
    0
  • Batalbalas