Login

Tag "encoding"

Snippet List

JSON Encoder for models

A simplejson encoder that knows how to encode django models, and it's little brother that also know how to deals with lazy translations.

  • models
  • json
  • encoding
Read More

JSON encoding middleware

Makes it really easy to return JSON from your views: just return a dict. (Also from [django-webapp](http://code.google.com/p/django-webapp/).)

  • middleware
  • serialize
  • json
  • encode
  • encoding
  • serializer
Read More

Character encoding fix

There is a commonly encountered problem with Django and character sets. Windows applications such as Word/Outlook add characters that are not valid ISO-8859-1 and this results in problems saving a Django model to a database with a Latin 1 encoding. These characters should also be converted to avoid any display issues for the end users even if you are using a UTF-8 database encoding. The topic is well covered at [Effbot](http://effbot.org/zone/unicode-gremlins.htm) and contains a list of appropriate conversions for each of hte problem characters. Correcting this for all of your Django models is another issue. Do you handle the re-encoding during the form validation? The save for each model? Create a base class that all your models need to inherit from? The simplest solution I have created leverages [Signals](http://code.djangoproject.com/wiki/Signals) Combining the re-encoding method suggested at Effbot and the pre_save signal gives you the ability to convert all the problem characters right before the save occurs for any model. **kill_gremlins method replaced with Gabor's suggestion**

  • django
  • python
  • unicode
  • latin1
  • character
  • encoding
Read More

4 snippets posted so far.