Fixed #19397 -- Crash on binary files in project templates.
Thanks gw 2012 at tnode com for the report.
This commit is contained in:
parent
2e2c4968f6
commit
baae4b8187
|
@ -8,8 +8,6 @@ import shutil
|
||||||
import stat
|
import stat
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import codecs
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from urllib.request import urlretrieve
|
from urllib.request import urlretrieve
|
||||||
except ImportError: # Python 2
|
except ImportError: # Python 2
|
||||||
|
@ -156,12 +154,14 @@ class TemplateCommand(BaseCommand):
|
||||||
|
|
||||||
# Only render the Python files, as we don't want to
|
# Only render the Python files, as we don't want to
|
||||||
# accidentally render Django templates files
|
# 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()
|
content = template_file.read()
|
||||||
if filename.endswith(extensions) or filename in extra_files:
|
if filename.endswith(extensions) or filename in extra_files:
|
||||||
|
content = content.decode('utf-8')
|
||||||
template = Template(content)
|
template = Template(content)
|
||||||
content = template.render(context)
|
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)
|
new_file.write(content)
|
||||||
|
|
||||||
if self.verbosity >= 2:
|
if self.verbosity >= 2:
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 894 B |
Loading…
Reference in New Issue