Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将外部CSS的内容直接导入Django模板?_Django_Django Templates - Fatal编程技术网

如何将外部CSS的内容直接导入Django模板?

如何将外部CSS的内容直接导入Django模板?,django,django-templates,Django,Django Templates,我有一个CSS文件,正在将其导入页面,如下所示: <html> <head> <link rel="stylesheet" href="{% static 'css/common.css' %}" /> </head> <body> Hello world. </body> </html> 你好,世界。 我想直接将CSS文件的内容导入模板。完成此过程后,模板应如下所示: &l

我有一个CSS文件,正在将其导入页面,如下所示:

<html>
  <head>
    <link rel="stylesheet" href="{% static 'css/common.css' %}" />
  </head>
  <body>
    Hello world.
  </body>
</html>

你好,世界。
我想直接将CSS文件的内容导入模板。完成此过程后,模板应如下所示:

<html>
  <head>
    <style type="text/css">
      /* this is the contents of common.css */
      body{ background: black; }
    </style>
  </head>
  <body>
    Hello world.
  </body>
</html>

/*这是common.css的内容*/
正文{背景:黑色;}
你好,世界。
也许有一个模板过滤器或类似的东西。我该怎么做


PS:标题中的“直接”表示此过程应在客户端得到响应之前完成。

您可以将
common.css
文件用作包含所有css属性的html文件
common.html

common.html

<style>
    // stuff 
</style>

我不知道这是最好的方法。也许还有另一个选择。。。
<head>
    {% include 'path/to/common.html' %}
</head>