id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux
18091,Non-ASCII templates break `django-admin.py startproject --template=TEMPLATE`,Antti Kaihola,nobody,"If a file in a project template for `manage.py startproject --template=TEMPLATE`
* has non-ASCII characters in its contents, and
* is named with one of the extensions given in the `--extension=` argument,
a !UnicodeDecodeError is raised:
{{{
$ django-admin.py startproject --template=mytemplate myproject
Traceback (most recent call last):
File ""/django/django/bin/django-admin.py"", line 5, in
management.execute_from_command_line()
File ""django/core/management/__init__.py"", line 442, in execute_from_command_line
utility.execute()
File ""django/core/management/__init__.py"", line 381, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File ""django/core/management/base.py"", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File ""django/core/management/base.py"", line 231, in execute
output = self.handle(*args, **options)
File ""django/core/management/commands/startproject.py"", line 31, in handle
super(Command, self).handle('project', project_name, target, **options)
File ""django/core/management/templates.py"", line 161, in handle
new_file.write(content.encode('UTF-8'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 113: ordinal not in range(128)
}}}
The content of the template file is read from the disk as a bytestring (line 156) and run through the Django template engine, which outputs the rendered text as a Unicode object (line 159). The Unicode object is then attempted to be written in to a file without encoding it first (line 161).
Files whose extension '''isn't''' included in `--extension=` are read from the disk, '''not''' run through the template engine and written back to the destination without any decoding or encoding. For this reason, those files are handled without problems even if they have non-ASCII content.",Bug,closed,Core (Management commands),master,Normal,fixed,,Clo74 Florian Apolloner tomas.ehrlich@…,Accepted,1,0,0,0,0,0