gpt4 book ai didi

python - Django 模板扩展

转载 作者:行者123 更新时间:2023-11-28 02:43:36 25 4
gpt4 key购买 nike

可能是一件非常容易解决的事情,但我有一个网页模板,该模板有一些在表面链接的通用 CSS。

<html>
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'css/index.css' %}">
....

*navbar code in body
{%block content%}{%endblock%}
</html>

对于任何扩展的 html 页面,它们将具有此布局以及一些其他个性化的 CSS。如何在不覆盖当前 CSS 的情况下从静态文件夹添加更多自定义 CSS?

{% extends "template.html" %}
{% load static %}

?Insert custom css for the specific page?

{% block content %}
*CONTENT*
{%blockend%}

最佳答案

使用模板 block ( https://docs.djangoproject.com/en/1.7/topics/templates/ )。

基础模板(template.html):

{% load static %}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="{% static 'css/index.css' %}">
{% block extra_css %}{% endblock %}
</head>
...

子模板:

{% extends "template.html" %}
{% load static %}

{% block extra_css %}
<!-- Specific template css here -->
<link rel="stylesheet" type="text/css" href="{% static 'css/another.css' %}">
{% endblock %}

关于python - Django 模板扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47037853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com