Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8400977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:41:21+00:00 2026-06-09T21:41:21+00:00

In django, we can do this: views.py : def A(request): context = {test :

  • 0

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’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:41:22+00:00Added an answer on June 9, 2026 at 9:41 pm

    From the mako Docs on Context Variables:

    % if someval is UNDEFINED:
        someval is: no value
    % else:
        someval is: ${someval}
    % endif
    

    The docs describe this as referencing variable names not in the current context. Mako will set these variables to the value UNDEFINED.

    I check for variables like so:

    % if not someval is UNDEFINED:
        (safe to use someval)
    

    However, if pylons/pyramid has strict_undefined=True setting, attempts to use the undefined variable results in a NameError being raised. They give a brief philisophical justification for doing it this way, instead of simply replacing un-set variables with empty strings which seems consistent with Python philosophy. Took me a while to find this, but reading that entire section on the Mako Runtime will clear up how Mako recieves, sets, and uses context variables.

    Edit:
    For completions sake, the documents explain the strict_undefined setting here. You can change this variable by setting it in one of your .ini files:

    [app:main]
    ...
    mako.strict_undefined = false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my view, if I specify def myView(request): return render_to_response('myTemplate.html', {'user': request.user,}, context_instance=RequestContext(request)) then
i have a django 'templating' question if i have in views.py: def cv(request): if
My views.py code: from django.template import Context, loader, RequestContext from django.http import HttpResponse from
The docs for django.core.files.File imply I can do this: print File(open(path)).url but the File
Why can't I do this? from django import forms from django.forms import widgets class
I am sending an AJAX request to a Django view that can potentially take
How can I increase django execution time of a view. Some views of my
I keep getting this error on my views. I can't work it out as
This view function: @login_required def dashboard(request): from myproject.myapp.models import UserProfile k = UserProfile.objects.get( user=request.user.pk
In one of my views the following function being called like def post_list(request, page=0,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.