简体   繁体   English

能否在Django中为扩展的html模板定义单独的css文件?

[英]Can one define a separate css file for an extending html template in Django?

Assume that abc.html extends base.html in a django app. 假设abc.html在django应用程序中扩展了base.html。

I noticed that I have to do the styling of abc.html inside the css file of base.html (say base.css) 我注意到我必须在base.html的CSS文件中进行abc.html的样式设置(例如base.css)

I was wondering there is a way to define a separate (independent) css file for abc.html and manage the styling using base.css and abc.css files for example? 我想知道是否有一种方法可以为abc.html定义一个单独的(独立的)css文件,并使用例如base.css和abc.css文件管理样式? I tried to follow the same steps to use , and tags inside abc.html and define a link to abc.css file, but django was not picking it up. 我尝试按照相同的步骤使用,并在abc.html中添加标签,并定义了一个指向abc.css文件的链接,但django没有选择它。

Have a block inside your base.html containing your CSS file. 在base.html中有一个包含CSS文件的块。 Example: 例:

{% block base.css %}

When you extend your base.html, replace the content within block with your new css file. 扩展base.html时,将块中的内容替换为新的CSS文件。

Or use {{ block.super }} after abc.html css. 或在abc.html CSS之后使用{{ block.super }}

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM