pylons mako how to check if variable exist or not

Viewed 6454

In django, we can do this:

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

And have our template render without error, even if i use method B, where variable 'test' does not exist, but I still can put it in the template.

I want to do the same with pylons + mako, in controller :

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

In Django, I can do that, but in Pylons, I get an error, is there anyway to check wheter 'c.test' exists or not?

the error : AttributeError: 'ContextObj' object has no attribute 'test'

3 Answers
Related