Browse files

Fixed #18091 -- Non-ASCII templates break ` startproje…

…ct --template=TEMPLATE`.

Thanks to Claude Huchet and Tomáš Ehrlich for the patch.
  • Loading branch information...
apollo13 committed Aug 28, 2012
1 parent 20012b9 commit 3afb5916b215c79e36408b729c9516bc435f5cb7
@@ -8,6 +8,8 @@
import stat
import sys
import tempfile
import codecs
from urllib.request import urlretrieve
except ImportError: # Python 2
@@ -154,12 +156,12 @@ def handle(self, app_or_project, name, target=None, **options):
# Only render the Python files, as we don't want to
# accidentally render Django templates files
with open(old_path, 'r') as template_file:
with, 'r', 'utf-8') as template_file:
content =
if filename.endswith(extensions) or filename in extra_files:
template = Template(content)
content = template.render(context)
with open(new_path, 'w') as new_file:
with, 'w', 'utf-8') as new_file:
if self.verbosity >= 2:
@@ -0,0 +1,2 @@
Some non-ASCII text for testing ticket #18091:
üäö €
@@ -1573,3 +1573,16 @@ def test_custom_project_destination_missing(self):
self.assertOutput(err, "Destination directory '%s' does not exist, please create it first." % testproject_dir)
def test_custom_project_template_with_non_ascii_templates(self):
"Ticket 18091: Make sure the startproject management command is able to render templates with non-ASCII content"
template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template')
args = ['startproject', '--template', template_path, '--extension=txt', 'customtestproject']
testproject_dir = os.path.join(test_dir, 'customtestproject')
out, err = self.run_django_admin(args)
self.addCleanup(shutil.rmtree, testproject_dir)
self.assertEqual(open(os.path.join(testproject_dir, 'ticket-18091-non-ascii-template.txt')).read(),
'Some non-ASCII text for testing ticket #18091:\n\xc3\xbc\xc3\xa4\xc3\xb6 \xe2\x82\xac\n')

0 comments on commit 3afb591

Please sign in to comment.