문제

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

도움이 되었습니까?

해결책

include this in the head of your file:

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

and then use this:

u'áéíóú'

다른 팁

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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top