5👍
I haven’t test it with japanese language, but it works with some other languages like portuguese with special characters:
Add this on your settings.py
DEFAULT_FILE_STORAGE = 'app.models.ASCIIFileSystemStorage'
And your app.models.ASCIIFileSystemStorage
# This Python file uses the following encoding: utf-8
from django.db import models
from django.core.files.storage import FileSystemStorage
import unicodedata
class ASCIIFileSystemStorage(FileSystemStorage):
"""
Convert unicode characters in name to ASCII characters.
"""
def get_valid_name(self, name):
name = unicodedata.normalize('NFKD', name).encode('ascii', 'ignore')
return super(ASCIIFileSystemStorage, self).get_valid_name(name)
2👍
Your error is raised by the os.stat(path)
call, which means your filesystem doesn’t support japanese characters (actually it probably only support either ascii or some latin-xxx or windows-yyy encoding).
You have mainly two solutions here: either configure your system to use utf-8 everywhere (which is IMVHO a sane thing to do anyway), or make sure you only use your system encoding (or just plain ascii) for filesystem names etc (cf leeeandroo’s answer).
-1👍
add encode utf-8 then it can accept most languages
also to the templates html use charset utf-8
# -*- coding: UTF-8 -*- in at the top the file
<meta charset="utf-8"/> in html templates
edit:
please read official doc or add this line
from __future__ import unicode_literals
- [Django]-When does the queryset use its _result_cache, not hitting the database?
- [Django]-Deleting the tags that are not used by any other object
- [Django]-Errors while installing python packages
- [Django]-Django unique filename method
- [Django]-How to use a different database for Heroku review apps?