Change themes, layout template and css on django site

On my django site, I want to offer several themes for our best customers and for the boss. So I quickly created the following. β€œI'm glad I agreed to introduce it, but there are a few dirty hacks that I want to eliminate with the help of the nice decisions I ask for.”

Here is my hack

base.html says (be careful - ugly!)

{% ifequal theme "0" %}
    {% include "base_d0.html" %}
{% endifequal %}

{% ifequal theme "1" %}
    {% include "base_d1.html" %}
{% endifequal %}

{% ifequal theme "2" %}
    {% include "base_d2.html" %}
{% endifequal %}

Then I saved in MEDIA dir subdirs for all common css and js

and created tear

static/
  d0/     ( all theme 0 stuff )
    css/
    js/
  d1/     ( all theme 1 stuff )
    css/
    js/
  ...
  css/
    (all common css)
  js/
    (all common js)

My controller has a design switching method, the current one is stored in a cookie. It is checked with every request and in the template the PREFIX_STATICcontext variable corresponding to /mypathto/static/d0 resp. +d1 +d2, and, of course, I had to invent COMMON_STATICvar. And the var theme is also set for the base.html switch.

, googled , ( , )

+1
1

from loader_tags.py Include_Node do_extends doc:

This tag may be used in two ways: ``{% extends "base" %}`` (with quotes)
uses the literal value "base" as the name of the parent template to extend,
or ``{% extends variable %}`` uses the value of ``variable`` as either the
name of the parent template to extend (if it evaluates to a string) or as
the parent tempate itelf (if it evaluates to a Template object).

, ,

{% extends base %} 

{% extends "base.html" %}

var "base" theme + "/base.html" , get_template

+3

Source: https://habr.com/ru/post/1775920/


All Articles