Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed #14777 -- Added docs on working around the Python CSV m…

…odule's lack of Unicode support. Thanks to adamv for the report and draft patch.

Backport of [14749] from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14750 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 3d07bb71c6ffc225e6d3a32975f6855b2561e85a 1 parent 3c951d9
authored November 29, 2010

Showing 1 changed file with 25 additions and 2 deletions. Show diff stats Hide diff stats

  1. 27  docs/howto/outputting-csv.txt
27  docs/howto/outputting-csv.txt
@@ -56,12 +56,35 @@ mention:
56 56
       about escaping strings with quotes or commas in them. Just pass
57 57
       ``writerow()`` your raw strings, and it'll do the right thing.
58 58
 
  59
+Handling Unicode
  60
+~~~~~~~~~~~~~~~~
  61
+
  62
+Python's ``csv`` module does not support Unicode input. Since Django uses
  63
+Unicode internally this means strings read from sources such as
  64
+:class:`~django.http.HttpRequest` are potentially problematic. There are a few
  65
+options for handling this:
  66
+
  67
+    * Manually encode all Unicode objects to a compatible encoding.
  68
+
  69
+    * Use the ``UnicodeWriter`` class provided in the `csv module's examples
  70
+      section`_.
  71
+
  72
+    * Use the `python-unicodecsv module`_, which aims to be a drop-in
  73
+      replacement for ``csv`` that gracefully handles Unicode.
  74
+
  75
+For more information, see the Python `CSV File Reading and Writing`_
  76
+documentation.
  77
+
  78
+.. _`csv module's examples section`: http://docs.python.org/library/csv.html#examples
  79
+.. _`python-unicodecsv module`: https://github.com/jdunck/python-unicodecsv
  80
+.. _`CSV File Reading and Writing`: http://docs.python.org/library/csv.html
  81
+
59 82
 Using the template system
60 83
 =========================
61 84
 
62 85
 Alternatively, you can use the :doc:`Django template system </topics/templates>`
63  
-to generate CSV. This is lower-level than using the convenient CSV, but the
64  
-solution is presented here for completeness.
  86
+to generate CSV. This is lower-level than using the convenient Python ``csv``
  87
+module, but the solution is presented here for completeness.
65 88
 
66 89
 The idea here is to pass a list of items to your template, and have the
67 90
 template output the commas in a :ttag:`for` loop.

0 notes on commit 3d07bb7

Please sign in to comment.
Something went wrong with that request. Please try again.