Python Django无法读取变量
我对django有意见 在我看来,我有这个Python Django无法读取变量,python,django,model,processors,Python,Django,Model,Processors,我对django有意见 在我看来,我有这个 def home(request): template = "index.html" test = "hello" Settings = settings.objects.all() return render_to_response(template ,{"Settings" : settings}, context_instance=RequestContext(request)) 在我的index.html中 {
def home(request):
template = "index.html"
test = "hello"
Settings = settings.objects.all()
return render_to_response(template ,{"Settings" : settings}, context_instance=RequestContext(request))
在我的index.html中
{{test}}
但它不会返回任何东西
如果我写的话,我的模型还有一个名为logo_img的字段
{{ Settings.logo_img }}
也不起作用,有什么想法吗?用hello呈现测试变量:
def home(request):
template = "index.html"
test = "hello"
return render_to_response(template, {"test": test})
只要模板目录配置正确,并且找到index.html,这应该可以工作。
我不确定您使用变量设置的目的是什么。在您分配它之后,它没有被引用。它起作用了:D thz,我还有一个问题,有没有一种方法可以返回设置模型,但不使用{%for%}?