Skip to content

Commit

Permalink
Fixed #19397 -- Crash on binary files in project templates.
Browse files Browse the repository at this point in the history
Thanks gw 2012 at tnode com for the report.
  • Loading branch information
aaugustin committed Dec 3, 2012
1 parent 2e2c496 commit baae4b8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions django/core/management/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import stat
import sys
import tempfile
import codecs

try:
from urllib.request import urlretrieve
except ImportError: # Python 2
Expand Down Expand Up @@ -156,12 +154,14 @@ 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 codecs.open(old_path, 'r', 'utf-8') as template_file:
with open(old_path, 'rb') as template_file:
content = template_file.read()
if filename.endswith(extensions) or filename in extra_files:
content = content.decode('utf-8')
template = Template(content)
content = template.render(context)
with codecs.open(new_path, 'w', 'utf-8') as new_file:
content = content.encode('utf-8')
with open(new_path, 'wb') as new_file:
new_file.write(content)

if self.verbosity >= 2:
Expand Down
Binary file not shown.

0 comments on commit baae4b8

Please sign in to comment.