Django模板:从文件中嵌入css [英] Django template: Embed css from file

查看:314
本文介绍了Django模板:从文件中嵌入css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个电子邮件模板,因此我想嵌入一个css文件

I'm working on an email template, therefor I would like to embed a css file

<head>
   <style>{{ embed 'css/TEST.css' content here }}</style>
</head>

而非链接

<head>
   <link href="{% static 'css/TEST.css' %}" rel="stylesheet" type="text/css">
</head>

任何想法?

推荐答案

我想你可以使用 include

<style>{% include "/static/css/style.css" %}</style>    

https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#include

但是在视图中加载css文件的内容可能会更好,并将其放在视图的上下文中以将其发送到模板

But it might be better to load the contents of the css file in your view, and put it in the context of your view to send it to the template

这篇关于Django模板:从文件中嵌入css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆