Inlining CSS is necessary for email generation and sending but is currently a suprisingly large hassle.
This library aims to make it a breeze in the Django template language.
- BeautifulSoup
- cssutils
- Python 2.6+
- Django 1.4+
Add django_inlinecss
to your settings.py
:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.webdesign',
'django.contrib.contenttypes',
'...',
'...',
'...',
'django_inlinecss')
- Place your CSS file somewhere staticfiles can find it
- Create your template:
{% load inlinecss %}
{% inlinecss "css/extra-padding.css" %}
<html>
<body>
<div class='lots-o-padding'>
Something in need of styling.
</div>
</body>
</html>
{% endinlinecss %}
<html>
<body>
<div style="padding-left: 10px; padding-right: 10px; padding-top: 10px;" class="lots-o-padding">
Something in need of styling.
</div>
</body>
</html>
Thanks to Tanner Netterville for his efforts on Pynliner.
Thanks to Thomas Yip for his unit tests on the soupselect
module. These tests
helped on getting the core CSS2 selectors to work.
MIT license. See LICENSE.md for more detail.