Pergunta

How do I use letters with accent marks or special characters like ñ in verbose_name or help_text?

Foi útil?

Solução

include this in the head of your file:

# -*- coding: utf-8 -*-

and then use this:

u'áéíóú'

Outras dicas

i did it:

import os, sys
#encoding= utf-8

Thanks

@diegueus9 has the right answer for using raw Unicode characters in the source file. Use whatever characters you like as long as you declare the encoding as per the instructions in PEP263. However, for using just a few special characters you may find this easier: declare the string as Unicode with the u prefix and use the character's code point. The following are equivalent ways of writing "ñ":

help_text=u'\xF1 \u00F1 \U000000F1'

When it comes to actually finding the code point for a character...that's a little harder. Windows has the useful Character Map utility. gucharmap is similar. The charts at unicode.org provide alphabet-specific PDFs you can search through. Anyone know an easier way?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top