mirror of
https://github.com/django/django.git
synced 2025-11-25 05:04:26 +00:00
Fixed #31789 -- Added a new headers interface to HttpResponse.
This commit is contained in:
parent
71ae1ab012
commit
bcc2befd0e
47 changed files with 385 additions and 256 deletions
|
|
@ -21,7 +21,7 @@ Here's an example::
|
|||
def some_view(request):
|
||||
# Create the HttpResponse object with the appropriate CSV header.
|
||||
response = HttpResponse(content_type='text/csv')
|
||||
response['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
|
||||
response.headers['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
|
||||
|
||||
writer = csv.writer(response)
|
||||
writer.writerow(['First row', 'Foo', 'Bar', 'Baz'])
|
||||
|
|
@ -88,7 +88,7 @@ the assembly and transmission of a large CSV file::
|
|||
writer = csv.writer(pseudo_buffer)
|
||||
response = StreamingHttpResponse((writer.writerow(row) for row in rows),
|
||||
content_type="text/csv")
|
||||
response['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
|
||||
response.headers['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
|
||||
return response
|
||||
|
||||
Using the template system
|
||||
|
|
@ -109,7 +109,7 @@ Here's an example, which generates the same CSV file as above::
|
|||
def some_view(request):
|
||||
# Create the HttpResponse object with the appropriate CSV header.
|
||||
response = HttpResponse(content_type='text/csv')
|
||||
response['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
|
||||
response.headers['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
|
||||
|
||||
# The data is hard-coded here, but you could load it from a database or
|
||||
# some other source.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue