Hi Dirk, On Thu, 2006-10-05 at 14:05 +0200, Dirk Eschler wrote: > Hi, > > in PHP *shrug* i used to pipe user input through htmlentities() before i > stored it in a database. Basically to avoid encoding issues with German > special chars. > > ä -> ä > Ö -> Ö > ß -> ß > etc. > > How can i achieve this when defining a model in Django? Or is it a bad > pratice > and there's a better way? Sorry if this is obvious, but i can't seem to find > a good answer.
Python has an htmlentitydefs module and you can use that to convert unicode characters into the appropriate HTML entities. Django does not do anything like this by default, because it assumes that you are only ever going to be presenting the data as HTML for output purposes. If your input data is going to also be used to produce PDFs or CSV files, then converting to HTML entities is going to be more annoying than useful. If you want to do this conversion yourself, though, you need to write a function that maps each character's ordinal value through the dictionary htmlentitydefs.codepoint2name. This dictionary maps, for example, 223 to the string "szlig", so you need to put in the leading '&' and trailing ';' yourself. This may seem fiddly, but you only have to write the conversion function once and then call it for all your input. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---

