传递一个变量以显示在django模板中 [英] Passing a variable to display in django template
本文介绍了传递一个变量以显示在django模板中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
choices.py:
testvar ='这是一个测试变量'
views.py
from .choices import testvar
template.html
{{testvar}}
pre>
是吗?导入似乎正常工作,但字符串不显示。
谢谢。解决方案您的观点必须如下:
from django.shortcuts import render
def index(request):
testvar ='value'
return render ,'template.html',{'testvar':testvar})
你的价值观。
Hi I'm new to django and there's something I can't figure out. How exactly can I display a variable set in a different file?
choices.py:
testvar= 'This is a test variable'
views.py
from .choices import testvar
template.html
{{testvar}}
Is that it? The import seems to work properly but the string doesn't show. Thanks.
解决方案Your view has to be something like:
from django.shortcuts import render def index(request): testvar = 'value' return render(request, 'template.html',{'testvar':testvar})
You pass the dictionary that contains your values.
这篇关于传递一个变量以显示在django模板中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文