Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.5.x] Fixed #19397 -- Crash on binary files in project templates.

Thanks gw 2012 at tnode com for the report.

Backport of baae4b8.
  • Loading branch information...
commit c9a47fb379cab4c0fe9be27c9924236e75327bd0 1 parent 1b93499
Aymeric Augustin authored December 03, 2012
8  django/core/management/templates.py
@@ -8,8 +8,6 @@
8 8
 import stat
9 9
 import sys
10 10
 import tempfile
11  
-import codecs
12  
-
13 11
 try:
14 12
     from urllib.request import urlretrieve
15 13
 except ImportError:     # Python 2
@@ -156,12 +154,14 @@ def handle(self, app_or_project, name, target=None, **options):
156 154
 
157 155
                 # Only render the Python files, as we don't want to
158 156
                 # accidentally render Django templates files
159  
-                with codecs.open(old_path, 'r', 'utf-8') as template_file:
  157
+                with open(old_path, 'rb') as template_file:
160 158
                     content = template_file.read()
161 159
                 if filename.endswith(extensions) or filename in extra_files:
  160
+                    content = content.decode('utf-8')
162 161
                     template = Template(content)
163 162
                     content = template.render(context)
164  
-                with codecs.open(new_path, 'w', 'utf-8') as new_file:
  163
+                    content = content.encode('utf-8')
  164
+                with open(new_path, 'wb') as new_file:
165 165
                     new_file.write(content)
166 166
 
167 167
                 if self.verbosity >= 2:
BIN  tests/regressiontests/admin_scripts/custom_templates/project_template/ticket-19397-binary-file.ico
Binary file not shown

0 notes on commit c9a47fb

Please sign in to comment.
Something went wrong with that request. Please try again.