Django template: Embed css from file

2024/10/9 4:16:24

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>

instead of linking it

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

Any ideas?

Answer

You can use django-compressor package. It will add {% compress %} template tag that can join together bunch of JS or CSS files (or inlined code) and put it into template as new, big file or inlined code. For example to inline one CSS file, you can use:

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

You can add more CSS files into one compress tag, they will be concatenated together and wrapped into one <style>tag.

Check usage examples for more details.

https://en.xdnf.cn/q/70063.html

Related Q&A

handling async streaming request in grpc python

I am trying to understand how to handle a grpc api with bidirectional streaming (using the Python API).Say I have the following simple server definition:syntax = "proto3"; package simple;serv…

Add new column to a HuggingFace dataset

In the dataset I have 5000000 rows, I would like to add a column called embeddings to my dataset. dataset = dataset.add_column(embeddings, embeddings) The variable embeddings is a numpy memmap array of…

Django: how to order_by on a related field of a related field

Im using annotate to add a property to an object which I can then use for order_by. However, I want to annotate on a field of a relation on a relation. I know I should be able to get to the field someh…

How to extract the cell state and hidden state from an RNN model in tensorflow?

I am new to TensorFlow and have difficulties understanding the RNN module. I am trying to extract hidden/cell states from an LSTM. For my code, I am using the implementation from https://github.com/ay…

Python - Nested List to Tab Delimited File?

I have a nested list comprising ~30,000 sub-lists, each with three entries, e.g.,nested_list = [[x, y, z], [a, b, c]].I wish to create a function in order to output this data construct into a tab delim…

How to make sure buildout doesnt use the already installed packages?

I am trying to switch fully to buildout - but our development environment already has lot of stuff installed in /usr/lib/pythonxx/How can I make sure that buildout doesnt use the libraries installed on…

Can python setup.py install use wheels?

I am using setuptools. Is there a way to have the following command use wheels instead of source?python setup.py installIn particular, I have a custom package that requires pandas. While pandas insta…

Getting the last element of a level in a multiindex

I have a dataframe in this format:a b x 1 1 31 1 2 1 1 3 42 1 4 423 1 5 42 1 6 3 1 7 44 1 8 65437 1 9 73 2 1 5656 2 2 7 2 3 5 2 4 5 2 5 34a a…

Sphinx and JavaScript Documentation Workflow [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 5…

Getting two characters from string in python [duplicate]

This question already has answers here:Split string every nth character(19 answers)How to iterate over a list in chunks(40 answers)Closed last year.how to get in python from string not one character, b…