1

我对 django 有疑问在我的 views.py 中我有这个

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 }}

也不起作用,有什么想法吗?

4

1 回答 1

0

用“hello”渲染测试变量:

def home(request):
    template = "index.html"
    test = "hello"
    return render_to_response(template, {"test": test})

只要您的模板目录配置正确,并且找到了 index.html,这应该可以工作。我不确定您将变量“设置”用于什么目的。分配后它不会被引用。

于 2014-08-11T02:01:55.833 回答