summaryrefslogtreecommitdiff
path: root/docs/howto
diff options
context:
space:
mode:
authorTom Carrick <tom@carrick.eu>2020-09-15 12:43:37 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-10-07 09:19:57 +0200
commitdcb69043d0de45bb55998fc418d93c28bc7689ae (patch)
treeac58b959d8b749965841721e6cc2a58784bb51c3 /docs/howto
parent2e7cc95499f758a1c4aa036cbf1dcddf82a89ea2 (diff)
Fixed #32002 -- Added headers parameter to HttpResponse and subclasses.
Diffstat (limited to 'docs/howto')
-rw-r--r--docs/howto/outputting-csv.txt21
1 files changed, 13 insertions, 8 deletions
diff --git a/docs/howto/outputting-csv.txt b/docs/howto/outputting-csv.txt
index dc3cf57cfd..0026d0293a 100644
--- a/docs/howto/outputting-csv.txt
+++ b/docs/howto/outputting-csv.txt
@@ -20,8 +20,10 @@ Here's an example::
def some_view(request):
# Create the HttpResponse object with the appropriate CSV header.
- response = HttpResponse(content_type='text/csv')
- response.headers['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
+ response = HttpResponse(
+ content_type='text/csv',
+ headers={'Content-Disposition': 'attachment; filename="somefilename.csv"'},
+ )
writer = csv.writer(response)
writer.writerow(['First row', 'Foo', 'Bar', 'Baz'])
@@ -86,10 +88,11 @@ the assembly and transmission of a large CSV file::
rows = (["Row {}".format(idx), str(idx)] for idx in range(65536))
pseudo_buffer = Echo()
writer = csv.writer(pseudo_buffer)
- response = StreamingHttpResponse((writer.writerow(row) for row in rows),
- content_type="text/csv")
- response.headers['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
- return response
+ return StreamingHttpResponse(
+ (writer.writerow(row) for row in rows),
+ content_type="text/csv",
+ headers={'Content-Disposition': 'attachment; filename="somefilename.csv"'},
+ )
Using the template system
=========================
@@ -108,8 +111,10 @@ 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.headers['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
+ response = HttpResponse(
+ content_type='text/csv'
+ 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.