Django

Code

Show
Ignore:
Timestamp:
04/29/08 19:03:45 (3 months ago)
Author:
adrian
Message:

Added 'Setting headers' and 'Telling the browser to treat the response as a file attachment' sections to docs/request_response.txt

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/request_response.txt

    r7361 r7510  
    403403      object. Doing so will raise ``Exception``. 
    404404 
     405Setting headers 
     406~~~~~~~~~~~~~~~ 
     407 
     408To set a header in your response, just treat it like a dictionary:: 
     409 
     410    >>> response = HttpResponse() 
     411    >>> response['Pragma'] = 'no-cache' 
     412 
     413Telling the browser to treat the response as a file attachment 
     414~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     415 
     416To tell the browser to treat the response as a file attachment, use the 
     417``mimetype`` argument and set the ``Content-Disposition`` header. For example, 
     418this is how you might return a Microsoft Excel spreadsheet:: 
     419 
     420    >>> response = HttpResponse(my_data, mimetype='application/vnd.ms-excel') 
     421    >>> response['Content-Disposition'] = 'attachment; filename=foo.xls' 
     422 
     423There's nothing Django-specific about the ``Content-Disposition`` header, but 
     424it's easy to forget the syntax, so we've included it here. 
     425 
    405426Methods 
    406427------- 
     
    421442    header, it can also include the character set encoding, which makes it 
    422443    more than just a MIME type specification. If ``mimetype`` is specified 
    423     (not None), that value is used. Otherwise, ``content_type`` is used. If 
     444    (not ``None``), that value is used. Otherwise, ``content_type`` is used. If 
    424445    neither is given, the ``DEFAULT_CONTENT_TYPE`` setting is used. 
    425446