Felipe França
Felipe França

Reputation: 99

How to change a css item in a template using django admin?

I would like to know if there is some way to change a css class from a template page using django admin. I would like to put the django tag inside of css file.

example:

body {
    background-color: {{ body.color }};
    width: {{ body.width }};
}

Upvotes: 0

Views: 330

Answers (2)

Lars Wikman
Lars Wikman

Reputation: 366

You could also include your CSS file using template tags. That would demand a style tag but considering the dynamic approach here it's really not much of an issue:

<html>
    <head>
        <style type="text/css">
        {% include 'templates/mytemplate.css' %}
        </style>
    </head>
    <body></body>
</html>

The template could then be what you described above. Then the CSS template would have access to whatever data your base template has access too.

Depending on your use case you might also do something with blocks but I'm not sure that is worth exploring at this point.

Upvotes: 2

Hodson
Hodson

Reputation: 3556

Just off the top of my head:

  • Create a Model to store the CSS values you want
  • Register the Model to show up in the Admin Screens
  • In your views, return these values as a dictionary
  • In the template, use the values as you suggested

Upvotes: 1

Related Questions