Changes between Initial Version and Version 2 of Ticket #10730


Ignore:
Timestamp:
Apr 4, 2009, 2:34:26 PM (15 years ago)
Author:
Alex Gaynor
Comment:

Reformatted for readability, please use the preview button folks.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #10730

    • Property Resolutioninvalid
    • Property Status newclosed
  • Ticket #10730 – Description

    initial v2  
    11Hi, 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{{{
    33writer = csv.writer(response)
    44writer.writerow(['ID', 'NIT', 'Nombre', 'Direccion', 'Telefono', 'Ciudad'])
     
    1010                        cliente.ciudad
    1111                    ])
    12 
     12}}}
    1313When 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{{{
    1515writer = csv.writer(response)
    1616writer.writerow(['ID', 'NIT', 'Nombre', 'Direccion', 'Telefono', 'Ciudad'])
     
    2222                        cliente.ciudad
    2323                    ])
    24 
     24}}}
    2525Using 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?
    2626
Back to Top