0

IM try to upload a file but when the file name have caracters like "ó" have a 'ascii' codec can't encode character u'\xf3' in position 59: ordinal not in range(128) im try to obj.file = smart_unicode(form.cleaned_data["file"]) before save() on views.py

and

def file(instance, filename):
    i = datetime.now()
    filename = smart_unicode(filename)

    return "archivos/files/%s_%s" % (str("a")+i.strftime('%Y-%m-%d'), filename)

on models.py, but when using view.py dont have error and on saved model have the name file correct but dont have file, and when not using smart_unicode have error, with out especial caracter font have problem to upload.

1 Answer 1

1

this url have information about, Django: How to upload file without UnicodeEncodeError on save()?

an for me work this:

import locale
import sys

def my_views(request):
    # before 
    reload(sys)
    sys.setdefaultencoding("utf-8")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.