我正在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'?
什麼是輸出這段代碼? –