0
我正在爲我的Django
網站創建一些主題,我想修改context_processors variable
函數中的HTML文本顏色。Django「if」條件與context_processors變量
的context_processors變量是:數據系統或喀麥隆(I有兩個主題到現在爲止,但我將在結束時也許4或5的主題)。
所以,如果變量是數據系統,文本的顏色應該是藍色的。如果變量是Cameroun,文本的顏色應該是綠色的。
我context_processors.py(它完美的作品)文件的樣子:
from django.conf import settings
from Configurations.models import Theme
def GetTheme(request):
return {'mytheme' : Theme.objects.values_list('favorite_theme').last()[0].encode("ascii")}
我的HTML模板的樣子:
{% extends 'Base_Accueil.html' %}
{% load staticfiles %}
{% load static %}
{% block content %}
<p align="center"><img src="{% static 'images/logo.png' %}"></p>
{% if {% get_static_prefix %}{{ mytheme }} == "Datasystems" %}
<h2 align="center"> <font color="#0083A2"> Bienvenue sur la page d'accueil du logiciel DatasystemsEC</font></align></h2>
<p></p>
{% if {% get_static_prefix %}{{ mytheme }} == "Cameroun" %}
<h2 align="center"> <font color="#007A5E"> Bienvenue sur la page d'accueil du logiciel DatasystemsEC</font></align></h2>
<p></p>
{% endif %}
{% if user.is_authenticated %}
<h3 align="center"> <font color="#0083A2"> Vous êtes connecté(e) en tant que {{ user.username }} </font></align></h3>
{% endif %}
{% endblock content %}
我怎麼能執行此if
條件?
我不明白你爲什麼要在那裏使用'get_static_prefix'。無論如何,幾天前我沒有回答你的問題嗎? –
看起來你可能想'{%if mythe =='數據系統'%}',但我不明白你爲什麼試圖在if語句中包含'{%get_static_prefix%}'。 – Alasdair
@DanielRoseman我想我必須在調用我的context_processors變量之前編寫'get_static_prefix'。我沒有很好地閱讀關於此的文檔。你說得對,也許一週,但情況有些不同。我沒有將這個變量添加到具有'href'的路徑中,而是使用'if'語句。對不起,如果從你的角度來看是重複的 – Deadpool