diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-06-17 10:25:48 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-06-17 10:25:48 +0000 |
| commit | 2126d41aba06b50a288cc6a516d4531ced998822 (patch) | |
| tree | 2ed0e56153471e6076903c99fda834a5f78dd364 /django/template | |
| parent | 1bfcfe615c65565da5009a205aecff394217717c (diff) | |
unicode: Render templates as unicode objects and only convert them to
bytestrings as part of HttpRespnose and other output paths.
git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5487 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/template')
| -rw-r--r-- | django/template/__init__.py | 17 | ||||
| -rw-r--r-- | django/template/loader.py | 4 |
2 files changed, 7 insertions, 14 deletions
diff --git a/django/template/__init__.py b/django/template/__init__.py index 5b8cdc3b1f..422820f905 100644 --- a/django/template/__init__.py +++ b/django/template/__init__.py @@ -60,7 +60,7 @@ from django.conf import settings from django.template.context import Context, RequestContext, ContextPopException from django.utils.functional import curry, Promise from django.utils.text import smart_split -from django.utils.encoding import smart_unicode, smart_str, force_unicode +from django.utils.encoding import smart_unicode, force_unicode from django.utils.translation import ugettext as _ __all__ = ('Template', 'Context', 'RequestContext', 'compile_string') @@ -176,9 +176,9 @@ class Template(object): for subnode in node: yield subnode - def render(self, context, encoding=None): + def render(self, context): "Display stage -- can be called many times" - return self.nodelist.render(context, encoding) + return self.nodelist.render(context) def compile_string(template_string, origin): "Compiles template_string into NodeList ready for rendering" @@ -732,21 +732,14 @@ class Node(object): return nodes class NodeList(list): - # How invalid encoding sequences are handled. The default 'strict' is not - # appropriate, because the framework is not in control of all the string - # data. - codec_errors = 'replace' - - def render(self, context, encoding=None): - if encoding is None: - encoding = settings.DEFAULT_CHARSET + def render(self, context): bits = [] for node in self: if isinstance(node, Node): bits.append(self.render_node(node, context)) else: bits.append(node) - return ''.join([smart_str(b, encoding, errors=self.codec_errors) for b in bits]) + return ''.join([force_unicode(b) for b in bits]) def get_nodes_by_type(self, nodetype): "Return a list of all nodes of the given type" diff --git a/django/template/loader.py b/django/template/loader.py index d142e8951e..03e6f8d49d 100644 --- a/django/template/loader.py +++ b/django/template/loader.py @@ -87,7 +87,7 @@ def get_template_from_string(source, origin=None, name=None): """ return Template(source, origin, name) -def render_to_string(template_name, dictionary=None, context_instance=None, encoding=None): +def render_to_string(template_name, dictionary=None, context_instance=None): """ Loads the given template_name and renders it with the given dictionary as context. The template_name may be a string to load a single template using @@ -103,7 +103,7 @@ def render_to_string(template_name, dictionary=None, context_instance=None, enco context_instance.update(dictionary) else: context_instance = Context(dictionary) - return t.render(context_instance, encoding) + return t.render(context_instance) def select_template(template_name_list): "Given a list of template names, returns the first that can be loaded." |
