| | 405 | Setting headers |
|---|
| | 406 | ~~~~~~~~~~~~~~~ |
|---|
| | 407 | |
|---|
| | 408 | To set a header in your response, just treat it like a dictionary:: |
|---|
| | 409 | |
|---|
| | 410 | >>> response = HttpResponse() |
|---|
| | 411 | >>> response['Pragma'] = 'no-cache' |
|---|
| | 412 | |
|---|
| | 413 | Telling the browser to treat the response as a file attachment |
|---|
| | 414 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| | 415 | |
|---|
| | 416 | To tell the browser to treat the response as a file attachment, use the |
|---|
| | 417 | ``mimetype`` argument and set the ``Content-Disposition`` header. For example, |
|---|
| | 418 | this 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 | |
|---|
| | 423 | There's nothing Django-specific about the ``Content-Disposition`` header, but |
|---|
| | 424 | it's easy to forget the syntax, so we've included it here. |
|---|
| | 425 | |
|---|