9
我試圖使用simple_tag並設置上下文變量。我現在用的主幹版本的DjangoDjango simple_tag和設置上下文變量
from django import template
@register.simple_tag(takes_context=True)
def somefunction(context, obj):
return set_context_vars(obj)
class set_context_vars(template.Node):
def __init__(self, obj):
self.object = obj
def render(self, context):
context['var'] = 'somevar'
return ''
這並不設定的變量,但如果我做@register.tag
非常類似的東西它的工作原理,但對象參數沒有通過......
謝謝!
感謝,你的答案是完美的,非常感謝 – neolaser 2011-02-07 03:08:45