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