Code

Ticket #18091: 18091-startproject-non-ascii-templates.diff

File 18091-startproject-non-ascii-templates.diff, 667 bytes (added by akaihola, 2 years ago)

Avoid UnicodeDecodeError by encoding template engine output in UTF-8

Line 
1diff --git a/django/core/management/templates.py b/django/core/management/templates.py
2index b2a1226..cf3d190 100644
3--- a/django/core/management/templates.py
4+++ b/django/core/management/templates.py
5@@ -156,7 +156,7 @@ class TemplateCommand(BaseCommand):
6                     content = template_file.read()
7                 if filename.endswith(extensions) or filename in extra_files:
8                     template = Template(content)
9-                    content = template.render(context)
10+                    content = template.render(context).encode('UTF-8')
11                 with open(new_path, 'w') as new_file:
12                     new_file.write(content)
13