我有一个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>也许有一个模板过滤器或类似的东西。我该怎么做呢?
PS:标题中的“直接”意味着这个过程应该在客户端得到响应之前完成。
发布于 2018-06-04 01:43:29
您可以将common.css文件用作包含所有css属性的html文件common.html。
common.html
<style>
// stuff
</style>在您的模板中,您只需将其包含在head标记中
<head>
{% include 'path/to/common.html' %}
</head>https://stackoverflow.com/questions/50669003
复制相似问题