0

プロジェクトにdjangoフレームワークを使用しています。ビューを介してテンプレートに渡すオブジェクトがあります。ビューでコンテンツを印刷するとオブジェクトは正常に動作しますが、テンプレート html で使用するとエラーが発生します。render_to_response 関数を使用しています

render_to_response('template.html',context_instance=RequestContext(request,request_params))

エラーは

Value Error

Expected a Field, got a <type 'str'>

ビューでデータを送信しています

 request_params = {'data':my_object}
 return render_to_response('template.html',context_instance=RequestContext(request,request_params))
 #where my_object has variables like my_objects.variable1,my_objects.variable2

テンプレートでは、データを次のように取得しています。

...
{% if data %}
{{data.variable1}}
{% endif %}

どうすれば解決できますか?ありがとう

4

3 に答える 3

2

これは、応答を返す方法です。

return render_to_response('template.html',
                          request_params,
                          context_instance=RequestContext(request))
于 2013-09-17T11:39:22.950 に答える
1

Django 1.4 +を使用していると思います。long を取り除く 次のrender_to_response.ようにします。

from django.shortcuts import render

# In your view

return render(request, 'template_name.html', {'test':'test'})
于 2013-09-17T11:44:19.080 に答える