ジャンゴでは、これを行うことができます:
views.py :
def A(request):
context = {test : 'test'}
return render_to_response('index.html', context , context_instance = RequestContext(request))
def B(request):
context = {}
return render_to_response('index.html', context , context_instance = RequestContext(request))
index.html:
{% if test %}
{{ test }}
{% endif %}
method B
そして、変数'test'
が存在しない場所でを使用しても、テンプレートをエラーなしでレンダリングしますが、それでもテンプレートに入れることができます。
controller で pylons + mako で同じことをしたい:
foo.py
def A(self):
c.test = 'test'
return render('index.html')
def B(self):
return render('index.html')
index.html :
% if c.test:
${'c.test'}
% endif
Django ではそれを行うことができますが、Pylons ではエラーが発生します'c.test'
。存在するかどうかを確認する方法はありますか?
エラー: AttributeError: 'ContextObj' オブジェクトに属性 'test' がありません