I'm trying to create a file dynamically in Django:
response = HttpResponse(mimetype='text/txt')
response['Content-Disposition'] = 'attachment; filename=%s' % filename # UnicodeEncodeError
response.write('text')
return response
If I hardcode the filename it works properly, but if I try to create the filename from DB data that contains non-ascii characters (like ó) I get a UnicodeEncodeError exception. How can I use the DB filename without getting an exception?