[Django]-Django filename from database with non-ascii characters

4👍

from django.utils.encoding import smart_str
...

 response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(filename)

3👍

You can fix the problem on the Django side but there is no guarantee it will work in all browsers.

See the testcases at http://greenbytes.de/tech/tc2231/.

For more details on this see this question, which links to a snippet to handle most cases.

Leave a comment