Python 如何使用Flask安装CSS模板?
我正在尝试使用此模板: 这是我的文件目录:Python 如何使用Flask安装CSS模板?,python,css,flask,Python,Css,Flask,我正在尝试使用此模板: 这是我的文件目录: app - static [--] css (inside static) [--] images (inside static) [--] js (inside static) - templates 但图像仍无法正常加载: 有人知道为什么图像无法正确加载吗 您只需将HTML从网站转储到templates文件夹中,图像和CSS的所有href和src属性仍在使用相对链接。这些需要转换为使用Flas
app
- static
[--] css (inside static)
[--] images (inside static)
[--] js (inside static)
- templates
但图像仍无法正常加载:
有人知道为什么图像无法正确加载吗 您只需将HTML从网站转储到templates文件夹中,图像和CSS的所有href和src属性仍在使用相对链接。这些需要转换为使用Flask的静态文件功能 例如,要使CSS正常工作,请更改此行:
<link href="css/bootstrap.css" rel='stylesheet' type='text/css' />
非常感谢你的帮助。这花了一段时间,但在改变了他们所有的工作!
<link href="{{ url_for('static', filename='css/bootstrap.css') }}" rel='stylesheet' type='text/css' />
<img src="images/logo.png" title="Flat style" />
<img src="{{ url_for('static', filename='images/logo.png') }}" title="Flat style" />
from flask import Flask, render_template, url_for