Changes between Initial Version and Version 2 of Ticket #10730
- Timestamp:
- Apr 4, 2009, 2:34:26 PM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #10730
- Property Resolution → invalid
- Property Status new → closed
-
Ticket #10730 – Description
initial v2 1 1 Hi, i has to make a function to export a model data to a CSV file, i follow the docs, and works great, but later, when users began to use special characters in a field of the model, the function fails, this is the original function: 2 2 {{{ 3 3 writer = csv.writer(response) 4 4 writer.writerow(['ID', 'NIT', 'Nombre', 'Direccion', 'Telefono', 'Ciudad']) … … 10 10 cliente.ciudad 11 11 ]) 12 12 }}} 13 13 When someone save a value like "niños por la paz en día" the function raises a " Exception Value: 'ascii' codec can't encode character u'\xd1' in position 15: ordinal not in range(128) ", i look in many places for the answer, and found using enconde() may works, and eventually i solve the problem like this: 14 14 {{{ 15 15 writer = csv.writer(response) 16 16 writer.writerow(['ID', 'NIT', 'Nombre', 'Direccion', 'Telefono', 'Ciudad']) … … 22 22 cliente.ciudad 23 23 ]) 24 24 }}} 25 25 Using encode('utf-8') for the fields that maybe user has special characters. You guys, can do this better or inside django, the encode thing by default, just for saving time and make sure the code works everywhere? 26 26