Changeset 2809 for django/trunk/docs/outputting_csv.txt
- Timestamp:
- 05/01/06 20:31:56 (3 years ago)
- Files:
-
- django/trunk/docs/outputting_csv.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/outputting_csv.txt
r1172 r2809 31 31 32 32 import csv 33 from django. utils.httpwrappersimport HttpResponse33 from django.http import HttpResponse 34 34 35 35 def some_view(request): … … 50 50 browsers that the document is a CSV file, rather than an HTML file. If 51 51 you leave this off, browsers will probably interpret the output as HTML, 52 which w ouldresult in ugly, scary gobbledygook in the browser window.52 which will result in ugly, scary gobbledygook in the browser window. 53 53 54 54 * The response gets an additional ``Content-Disposition`` header, which 55 contains the name of the CSV file. This filename is arbitrary : Call it55 contains the name of the CSV file. This filename is arbitrary; call it 56 56 whatever you want. It'll be used by browsers in the "Save as..." 57 57 dialogue, etc. … … 80 80 Here's an example, which generates the same CSV file as above:: 81 81 82 from django. utils.httpwrappersimport HttpResponse83 from django. core.template import loader, Context82 from django.http import HttpResponse 83 from django.template import loader, Context 84 84 85 85 def some_view(request): … … 95 95 ) 96 96 97 t = loader.get_template('my_template_name ')97 t = loader.get_template('my_template_name.txt') 98 98 c = Context({ 99 99 'data': csv_data, … … 106 106 such as the ``mimetype='text/csv'`` -- is the same. 107 107 108 Then, create the template ``my_template_name ``, with this template code::108 Then, create the template ``my_template_name.txt``, with this template code:: 109 109 110 110 {% for row in data %}"{{ row.0|addslashes }}", "{{ row.1|addslashes }}", "{{ row.2|addslashes }}", "{{ row.3|addslashes }}", "{{ row.4|addslashes }}"
