import json from django.template import Template, Context css_template = """ body { background-color: {{ backgroun_color }}; } .mce-content-body { background-color: {{ backgroun_color }}; } .article { font-size: 1.5rem; text-overflow: wrap; color: #222; background-color: {{ backgroun_color }}; } .article a { text-decoration: none; color: #222; } .article a:hover { text-decoration: none; color: #222; } .article img { max-width: 100%; object-fit: contain; } """ def gen_article_css(article): try: options = json.loads(article.options) except: options = {} t = Template(css_template) c = Context({ 'backgroun_color': options.get('page_bg_color', '#ffffff') }) return t.render(c)