Changes between Initial Version and Version 3 of Ticket #29276


Ignore:
Timestamp:
Mar 30, 2018, 5:34:50 AM (7 years ago)
Author:
Claude Paroz
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #29276

    • Property Summary Advise to turn the headers of HTTPResponse from str to bytes automaticallyTurn the headers of HTTPResponse from str to bytes automatically
  • Ticket #29276 – Description

    initial v3  
    77That is to say, the sample as below in the official document is not precisely correct.
    88(Page: https://docs.djangoproject.com/en/2.0/ref/request-response/)
     9{{{
    910>>> response = HttpResponse(my_data, content_type='application/vnd.ms-excel')
    1011>>> response['Content-Disposition'] = 'attachment; filename="foo.xls"'
    11 
     12}}}
    1213The precise usage should be:
     14{{{
    1315>>> response['Content-Disposition'] = 'attachment; filename="foo.xls"'.encode('utf-8')
    14 
     16}}}
    1517Otherwise, everthing will out of control If I have a Chinse character in the filename.
    1618Wrong:
     19{{{
    1720>>> response['Content-Disposition'] = 'attachment; filename="中中中中中foo.xls"'
     21}}}
    1822Correct:
     23{{{
    1924>>> response['Content-Disposition'] = 'attachment; filename=中中中中中foo.xls'.encode('utf-8')
    20 
     25}}}
    2126Can we accept this ticket and do a minor improvement? Then we would happily only handle str in Django other than str and bytes together.
    2227Thanks.
Back to Top