python - Couldn't integrate a CSS file into my project
问题描述
I would like to connect my layout.html file with a CSS file so that every other page extending my layout.html has access to this CSS file.
That is the code:
layout.html
<!DOCTYPE html>
<html lang="de">
<head>
<title>Aufgabenzettel</title>
<link rel="stylesheet" href="/aufgabenzettel/static/css/main.css">
</head>
<body>
{% block body %}
{% endblock %}
</body>
</html>
index.html
{% extends "aufgabenzettel/layout.html" %}
{% block body %}
<h1>Meine Aufgaben</h1>
{% endblock %}
main.css
h1 {
color: aqua;
}
The href in layout.html is probably correct bacause I can be redirected to it in VS via ctrl + click. However, the h1 in index.html still appears in black instead of aqua... What am I doing wrong?
I appreciate every kind of help!
解决方案
First you have to add {% load static %}
at the top of your code where you want to use static
function in template and than you have to use static function like this {% static 'your_css_path_inside_static_directory' %}
eg.
{% load static %}
<!DOCTYPE html>
<html lang="de">
<head>
<title>Aufgabenzettel</title>
<link rel="stylesheet" href="{% static '/aufgabenzettel/static/css/main.css' %}">
</head>
<body>
{% block body %}
{% endblock %}
</body>
</html>
推荐阅读
- python - 无法使用漂亮的搜素从 Python 中的网页中提取图像
- php - 将长字符串分配给变量和随后将较小的字符串附加到变量之间在性能上有什么区别吗?
- windows - Golang os.Rename(
, ) 在 Windows 中不起作用 - node.js - gyp动词`which`失败错误:未找到:python2
- dart - onTap:在初始化程序错误中只能访问静态成员
- python - 保存 ImageField 时出现 IntegrityError:字段“路径”没有默认值
- excel - 如何计算单元格直到值大于 0?
- scala - 在 DataFrame 的每个分区内读取、转换和写入数据
- javascript - 如何在 JavaScript 地图函数中使用 React Native 中的复选框?
- regex - 无论中间的内容如何,如何选择特定的行