summaryrefslogtreecommitdiff
path: root/docs/howto
diff options
context:
space:
mode:
authorGabriel Hurley <gabehr@gmail.com>2010-11-29 06:24:14 +0000
committerGabriel Hurley <gabehr@gmail.com>2010-11-29 06:24:14 +0000
commit5f63c01b50761c4dd810025ee0ef5eb4783bd013 (patch)
tree54818349d753272e2cf16f61723564e175e063d2 /docs/howto
parenta0b3306349ad4368b842389774bfaf9174fae119 (diff)
Fixed #14777 -- Added docs on working around the Python CSV module's lack of Unicode support. Thanks to adamv for the report and draft patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14749 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/howto')
-rw-r--r--docs/howto/outputting-csv.txt27
1 files changed, 25 insertions, 2 deletions
diff --git a/docs/howto/outputting-csv.txt b/docs/howto/outputting-csv.txt
index 169114ff95..46e111d8af 100644
--- a/docs/howto/outputting-csv.txt
+++ b/docs/howto/outputting-csv.txt
@@ -56,12 +56,35 @@ mention:
about escaping strings with quotes or commas in them. Just pass
``writerow()`` your raw strings, and it'll do the right thing.
+Handling Unicode
+~~~~~~~~~~~~~~~~
+
+Python's ``csv`` module does not support Unicode input. Since Django uses
+Unicode internally this means strings read from sources such as
+:class:`~django.http.HttpRequest` are potentially problematic. There are a few
+options for handling this:
+
+ * Manually encode all Unicode objects to a compatible encoding.
+
+ * Use the ``UnicodeWriter`` class provided in the `csv module's examples
+ section`_.
+
+ * Use the `python-unicodecsv module`_, which aims to be a drop-in
+ replacement for ``csv`` that gracefully handles Unicode.
+
+For more information, see the Python `CSV File Reading and Writing`_
+documentation.
+
+.. _`csv module's examples section`: http://docs.python.org/library/csv.html#examples
+.. _`python-unicodecsv module`: https://github.com/jdunck/python-unicodecsv
+.. _`CSV File Reading and Writing`: http://docs.python.org/library/csv.html
+
Using the template system
=========================
Alternatively, you can use the :doc:`Django template system </topics/templates>`
-to generate CSV. This is lower-level than using the convenient CSV, but the
-solution is presented here for completeness.
+to generate CSV. This is lower-level than using the convenient Python ``csv``
+module, but the solution is presented here for completeness.
The idea here is to pass a list of items to your template, and have the
template output the commas in a :ttag:`for` loop.