开发者

Django dynamic css implementation

I have my little blog app, and I want to be able to change styles (not necessarily all) from admin page. What would be the 'right' way to implement dynamic style loading in django project? My own thoughts:

  • Edit css file through Python file I/O
  • Construct css file from database
  • Though both implementations have serious drawbacks. Thank you i开发者_JAVA百科n advance for your solutions.

    Edit: I would prefer ideas not django apps :)


    The "right" way to do this would be to define a single class at the top-level div (or even body), which determines the master style for that page. All the style-able elements in that page then inherit this style via the magic of cascading:

    .master-default {
        color: black;
    }
    .master-default .bordered {
        border: green;
    }
    .master-blue {
        color: blue;
    }
    .master-blue .bordered
        border: yellow;
    }
    

    and so on. Now your admin interface simply allows the user to determine the top-level master style, which you then use in your base template:

    <div id="master" class="{{ userprofile.master_style }}">
        <div class="bordered">Border colour will vary according to master style</a>
    </div>
    

    etc.

    0

    上一篇:

    下一篇:

    精彩评论

    暂无评论...
    验证码 换一张
    取 消

    最新问答

    问答排行榜