S
S
Sergey Ozeransky2013-01-22 19:04:08
Django
Sergey Ozeransky, 2013-01-22 19:04:08

Django filename with cyrillic?

Actually the problem is, I can’t upload a file containing Cyrillic in the name through the admin panel, I do this:

def make_upload_path(instance, filename):
    return u'instructions/%s' % smart_str(filename)

class File(models.Model):
    ...
    file = models.FileField(upload_to=make_upload_path)

    def __unicode__(self):
        return self.name

I also tried smart_unicode
Tell me what I'm doing wrong?
'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(
128
)
error \u043a\u0446\u0438\u044f_eng_01_INFO.doc'

Answer the question

In order to leave comments, you need to log in

4 answer(s)
G
galaxy, 2013-01-22
@galaxy

In general, probably the most correct option would be:
1. Leave

def make_upload_path(instance, filename):
    return u'instructions/%s' % filename

2. Fix the locale, because in an eight-bit locale, saving arbitrary Unicode names will not work. Who sets this locale - I don’t know, I would look at gunicorn’s launch scripts

G
galaxy, 2013-01-22
@galaxy

Somewhere he encodes your unicode name in ascii, feed him a regular string:

def make_upload_path(instance, filename):
    return (u'instructions/%s' % filename).encode('utf-8')

L
lexich, 2013-01-22
@lexich

If under Windows look mime with Cyrillic stackoverflow.com/questions/4237898/unicodedecodeerror-ascii-codec-cant-decode-byte-0xe0-in-position-0-ordinal

S
Sergey Ozeransky, 2013-01-23
@KREGI

It becomes interesting why it does not start from the config /etc/supervisor/conf.d/transactions.conf
/home/user/www/transactions/env/bin/python /home/user/www/transactions/manage.py run_gunicorn -- bind=localhost:8000 --log-file /home/user/www/transactions/logs/gunicorn_error.log
and if you just execute this line, then everything is ok. but it won’t work there, you need it to start itself through the supervisor (installed)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question