Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

unicode: Added (optional) explicit template encoding specification. A…

…lso ported

contrib.sitemaps over (we want to ensure the output XML is in a valid encoding,
so we force UTF-8 in this case).


git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5277 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 52b0051523cb6608bf401aff9a42bc88567606cc 1 parent a8404e6
@malcolmt malcolmt authored
View
2  django/contrib/sitemaps/views.py
@@ -26,5 +26,5 @@ def sitemap(request, sitemaps, section=None):
urls.extend(site().get_urls())
else:
urls.extend(site.get_urls())
- xml = loader.render_to_string('sitemap.xml', {'urlset': urls})
+ xml = loader.render_to_string('sitemap.xml', {'urlset': urls}, encoding='utf-8')
return HttpResponse(xml, mimetype='application/xml')
View
9 django/template/__init__.py
@@ -176,9 +176,9 @@ def __iter__(self):
for subnode in node:
yield subnode
- def render(self, context):
+ def render(self, context, encoding=None):
"Display stage -- can be called many times"
- return self.nodelist.render(context)
+ return self.nodelist.render(context, encoding)
def compile_string(template_string, origin):
"Compiles template_string into NodeList ready for rendering"
@@ -730,14 +730,15 @@ class NodeList(list):
# data.
codec_errors = 'replace'
- def render(self, context):
+ def render(self, context, encoding=None):
+ if encoding is None:
+ encoding = settings.DEFAULT_CHARSET
bits = []
for node in self:
if isinstance(node, Node):
bits.append(self.render_node(node, context))
else:
bits.append(node)
- encoding = settings.DEFAULT_CHARSET
return ''.join([smart_str(b, encoding, errors=self.codec_errors) for b in bits])
def get_nodes_by_type(self, nodetype):
View
4 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):
+def render_to_string(template_name, dictionary=None, context_instance=None, encoding=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):
context_instance.update(dictionary)
else:
context_instance = Context(dictionary)
- return t.render(context_instance)
+ return t.render(context_instance, encoding)
def select_template(template_name_list):
"Given a list of template names, returns the first that can be loaded."
View
6 django/test/utils.py
@@ -10,10 +10,10 @@
# the test database.
TEST_DATABASE_PREFIX = 'test_'
-def instrumented_test_render(self, context):
- """An instrumented Template render method, providing a signal
+def instrumented_test_render(self, context, unused=None):
+ """
+ An instrumented Template render method, providing a signal
that can be intercepted by the test system Client
-
"""
dispatcher.send(signal=signals.template_rendered, sender=self, template=self, context=context)
return self.nodelist.render(context)
Please sign in to comment.
Something went wrong with that request. Please try again.