<分区>
我希望能够从 Django 中的所有模板调用 main.css 中的类。目前,我将其存储在 app_name/static/css/main.css 中。我如何将它链接到模板,以便我可以简单地将一个类添加到 html 元素并应用该类?
最佳答案
我会使用包含所有常见内容(JQuery、main.css)的基本模板。
因此,您将拥有一个名为 base.html
的模板,它将所有特定页面内容的基本内容和占位符:
<html>
<head>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}/css/main.css">
{% block additional_header %}
{% endblock %}
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
然后,您的实际页面将是一个模板,包含如下内容:
{% extends 'base.html' %}
{% block content %}
This is specific content for your page
{% endblock %}
Checkout Django's official documentation .查找标题为 Template Inheritance
的部分。
关于python - 如何将 main.css 链接到所有 Django 模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11904022/
相关文章:
html - 意外的 <body> body 行为,因为它被 child 的 margin-top 向下推
html - 对齐内容 : flex-end not shifting elements to container bottom
python - 函数参数的值既不是调用者传入的也不是默认值
django - 将 South 添加到 Django 项目、开发和生产中
python - 为什么 Pypy 添加 numpy 数组的速度较慢?
python - 模块 'pandas' 没有属性 'rolling_mean'