我正在django中开发一个应用程序,并在多个国家/地区提供支持。在网站上应根据所在的子域显示国旗,但我找不到通过django视图发送必要的国旗图像的方法。通过django视图上的字典更改图像
这是我的views.py
def index(request):
subdomain = request.META['HTTP_HOST'].split('.')[0]
if subdomain == 'www':
dic.update({"countryflag": ''})
elif subdomain == 'mx':
dic.update({"countryflag": '<img src="{% static "images/mxflag.png" %}" alt="img">'})
elif subdomain == 'nz':
dic.update({"countryflag": '<img src="{% static "images/nzflag.png" %}" alt="img">'})
return render(request, 'mysite/index.html', dic)
的例子,我想recive变量 “countryflag” 在我basetemplate.html
<div id="cp_side-menu-btn" class="cp_side-menu">
{{ countryflag }}
</div>
这不作品。我想将整个图像传递给countryflag键。有没有办法做到这一点,或者我必须在basetemplate.html中创建'if'?
什么是输出这段代码? –