diff --git a/django/core/management/templates.py b/django/core/management/templates.py
index b2a1226..cf3d190 100644
a
|
b
|
class TemplateCommand(BaseCommand):
|
156 | 156 | content = template_file.read() |
157 | 157 | if filename.endswith(extensions) or filename in extra_files: |
158 | 158 | template = Template(content) |
159 | | content = template.render(context) |
| 159 | content = template.render(context).encode('UTF-8') |
160 | 160 | with open(new_path, 'w') as new_file: |
161 | 161 | new_file.write(content) |
162 | 162 | |
diff --git a/tests/regressiontests/admin_scripts/custom_templates/project_template/ticket-18091-non-ascii-template.txt b/tests/regressiontests/admin_scripts/custom_templates/project_template/ticket-18091-non-ascii-template.txt
new file mode 100644
index 0000000..873eade
-
|
+
|
|
| 1 | Some non-ASCII text for testing ticket #18091: |
| 2 | üäö € |
diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py
index 4c4edbb..4b3ecf4 100644
a
|
b
|
class StartProject(LiveServerTestCase, AdminScriptTestCase):
|
1552 | 1552 | self.assertOutput(err, "Destination directory '%s' does not exist, please create it first." % testproject_dir) |
1553 | 1553 | self.assertFalse(os.path.exists(testproject_dir)) |
1554 | 1554 | |
| 1555 | def test_custom_project_template_with_non_ascii_templates(self): |
| 1556 | "Ticket 18091: Make sure the startproject management command is able to render templates with non-ASCII content" |
| 1557 | template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template') |
| 1558 | args = ['startproject', '--template', template_path, '--extension=txt', 'customtestproject'] |
| 1559 | testproject_dir = os.path.join(test_dir, 'customtestproject') |
| 1560 | |
| 1561 | out, err = self.run_django_admin(args) |
| 1562 | self.addCleanup(shutil.rmtree, testproject_dir) |
| 1563 | self.assertNoOutput(err) |
| 1564 | self.assertTrue(os.path.isdir(testproject_dir)) |
| 1565 | self.assertEqual(open(os.path.join(testproject_dir, 'ticket-18091-non-ascii-template.txt')).read(), |
| 1566 | 'Some non-ASCII text for testing ticket #18091:\n\xc3\xbc\xc3\xa4\xc3\xb6 \xe2\x82\xac\n') |