[Web-SIG] My original template API proposal

Ian Bicking ianb at colorstudy.com
Sun Feb 5 21:46:35 CET 2006

Ian Bicking wrote:
>       def render(template_instance, vars, format="html", fragment=False):

Here I can magically turn this into a WEB templating spec:

def render(template_instance, vars, format="html", fragment=False, 
wsgi_environ=None, set_header_callback=None)

wsgi_environ is the environ dictionary if this is being called in a WSGI 
context.  set_header_callback can be called like 
set_header_callback(header_name, header_value) to write such a header to 
the response.  Frameworks may or may not allow for setting headers.  If 
they don't allow for it, they shouldn't provide that callback (thus 
headers will not be mysteriously thrown away -- instead they will be 
rejected immediately).  [Should set_header_callback('Status', '404 Not 
Found') be used, or a separate callback, or...?]

This follows what all "server pages" templates I know of do.  That is, 
they do not have special syntax related to any metadata (i.e., headers) 
or even any special syntax related to web requests.  Instead the web 
request is represented through some set of variables available in the 

By putting these variables directly in the call to render(), we give a 
standard location for template languages to look for these values, and 
they can represent them internally however they choose.  This does not 
preclude sending request- or response-related values in through vars 

Ian Bicking  |  ianb at colorstudy.com  |  http://blog.ianbicking.org

More information about the Web-SIG mailing list