Answer the question
In order to leave comments, you need to log in
How to upload files with names in UTF-8 in Django Admin?
I ran into a problem: when uploading files to the server with Russian-language names, a
UnicodeEncodeError at /admin/dancercatalog/dancer/3/change/
'ascii' codec can't encode characters in position 78-84: ordinal not in range(128)
error occurs , everything works on a local machine under Windows
How to fix it ? Where to dig?
UnicodeEncodeError at /admin/dancerscatalog/dancer/3/change/
'ascii' codec can't encode characters in position 78-84: ordinal not in range(128)
Request Method: POST
Request URL: http://firesonu.beget.tech/admin/dancerscatalog/dancer/3/change/
Django Version: 2.0.6
Exception Type: UnicodeEncodeError
Exception Value:
'ascii' codec can't encode characters in position 78-84: ordinal not in range(128)
Exception Location: /home/f/firesonu/.local/lib/python3.4/genericpath.py in exists, line 19
Python Executable: /home/f/firesonu/.local/bin/python3
Python Version: 3.4.3
Python Path:
['/home/f/firesonu/firesonu.beget.tech/firepalace',
'/home/f/firesonu/.local/lib/python3.4/site-packages',
'/home/f/firesonu/firesonu.beget.tech',
'/opt/passenger40/helper-scripts',
'/home/f/firesonu/.local/lib/python34.zip',
'/home/f/firesonu/.local/lib/python3.4',
'/home/f/firesonu/.local/lib/python3.4/plat-linux',
'/home/f/firesonu/.local/lib/python3.4/lib-dynload',
'/home/f/firesonu/.local/lib/python3.4/site-packages']
Answer the question
In order to leave comments, you need to log in
This should not occur and it is better to find out the root cause, but a crutch is also possible:
from os.path import splitext
from transliterate import slugify
def slugify_upload(instance, filename):
name, ext = splitext(filename)
return slugify(name) + ext
class Dancer(models.Model):
photo = models.ImageFiled(upload_to=slugify_upload, ...)
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question