App Engine Python SDK  v1.6.9 rev.445
The Python runtime is available as an experimental Preview feature.
Namespaces | Classes | Functions | Variables
google.appengine._internal.django.template Namespace Reference

Namespaces

 defaultfilters
 
 defaulttags
 
 smartif
 

Classes

class  FilterExpression
 
class  InvalidTemplateLibrary
 
class  Lexer
 
class  Library
 
class  Node
 
class  NodeList
 
class  Origin
 
class  Parser
 
class  StringOrigin
 
class  Template
 
class  TemplateDoesNotExist
 
class  TemplateEncodingError
 
class  TemplateSyntaxError
 
class  TextNode
 
class  Token
 
class  TokenParser
 
class  Variable
 
class  VariableDoesNotExist
 
class  VariableNode
 

Functions

def compile_string
 
def resolve_variable
 
def generic_tag_compiler
 
def import_library
 
def get_templatetags_modules
 
def get_library
 
def add_to_builtins
 

Variables

tuple __all__ = ('Template', 'Context', 'RequestContext', 'compile_string')
 
int TOKEN_TEXT = 0
 
int TOKEN_VAR = 1
 
int TOKEN_BLOCK = 2
 
int TOKEN_COMMENT = 3
 
string FILTER_SEPARATOR = '|'
 
string FILTER_ARGUMENT_SEPARATOR = ':'
 
string VARIABLE_ATTRIBUTE_SEPARATOR = '.'
 
string BLOCK_TAG_START = '{%'
 
string BLOCK_TAG_END = '%}'
 
string VARIABLE_TAG_START = '{{'
 
string VARIABLE_TAG_END = '}}'
 
string COMMENT_TAG_START = '{#'
 
string COMMENT_TAG_END = '#}'
 
string SINGLE_BRACE_START = '{'
 
string SINGLE_BRACE_END = '}'
 
string ALLOWED_VARIABLE_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.'
 
string UNKNOWN_SOURCE = '<unknown source>'
 
tuple tag_re
 
dictionary libraries = {}
 
list builtins = []
 
 invalid_var_format_string = None
 
string constant_string = r""
 
string filter_raw_string = r""
 
tuple filter_re = re.compile(filter_raw_string, re.UNICODE|re.VERBOSE)
 
list templatetags_modules = []
 

Detailed Description

This is the Django template system.

How it works:

The Lexer.tokenize() function converts a template string (i.e., a string containing
markup with custom template tags) to tokens, which can be either plain text
(TOKEN_TEXT), variables (TOKEN_VAR) or block statements (TOKEN_BLOCK).

The Parser() class takes a list of tokens in its constructor, and its parse()
method returns a compiled template -- which is, under the hood, a list of
Node objects.

Each Node is responsible for creating some sort of output -- e.g. simple text
(TextNode), variable values in a given context (VariableNode), results of basic
logic (IfNode), results of looping (ForNode), or anything else. The core Node
types are TextNode, VariableNode, IfNode and ForNode, but plugin modules can
define their own custom node types.

Each Node has a render() method, which takes a Context and returns a string of
the rendered node. For example, the render() method of a Variable Node returns
the variable's value as a string. The render() method of an IfNode returns the
rendered output of whatever was inside the loop, recursively.

The Template class is a convenient wrapper that takes care of template
compilation and rendering.

Usage:

The only thing you should ever use directly in this file is the Template class.
Create a compiled template object with a template_string, then call render()
with a context. In the compilation stage, the TemplateSyntaxError exception
will be raised if the template doesn't have proper syntax.

Sample code:

>>> from google.appengine._internal.django.import template
>>> s = u'<html>{% if test %}<h1>{{ varvalue }}</h1>{% endif %}</html>'
>>> t = template.Template(s)

(t is now a compiled template, and its render() method can be called multiple
times with multiple contexts)

>>> c = template.Context({'test':True, 'varvalue': 'Hello'})
>>> t.render(c)
u'<html><h1>Hello</h1></html>'
>>> c = template.Context({'test':False, 'varvalue': 'Hello'})
>>> t.render(c)
u'<html></html>'

Function Documentation

def google.appengine._internal.django.template.get_library (   library_name)
Load the template library module with the given name.

If library is not already loaded loop over all templatetags modules to locate it.

{% load somelib %} and {% load someotherlib %} loops twice.

Subsequent loads eg. {% load somelib %} in the same process will grab the cached
module from libraries.
def google.appengine._internal.django.template.get_templatetags_modules ( )
Return the list of all available template tag modules.

Caches the result for faster access.
def google.appengine._internal.django.template.import_library (   taglib_module)
Load a template tag library module.

Verifies that the library contains a 'register' attribute, and
returns that attribute as the representation of the library
def google.appengine._internal.django.template.resolve_variable (   path,
  context 
)
Returns the resolved variable, which may contain attribute syntax, within
the given context.

Deprecated; use the Variable class instead.

Variable Documentation

tuple google.appengine._internal.django.template.tag_re
Initial value:
1 = re.compile('(%s.*?%s|%s.*?%s|%s.*?%s)' % (re.escape(BLOCK_TAG_START), re.escape(BLOCK_TAG_END),
2  re.escape(VARIABLE_TAG_START), re.escape(VARIABLE_TAG_END),
3  re.escape(COMMENT_TAG_START), re.escape(COMMENT_TAG_END)))