2014-02-23 38 views
3

当我添加一个parathesis到它的印在我的HTML与附加一个冒号以下标签字符串附加一个冒号:为什么我的字符串有当输出到HTML

question_3 = forms.MultipleChoiceField(choices=QUESTION_3_CHOICES, 
widget=forms.CheckboxSelectMultiple(), label = mark_safe('Which of 
these styles do you like? (choose multiple)')) 

在我的表单标签获取在我的HTML这样的输出:

Which of these styles do you like? (choose multiple): 

当我删除“(多选)”,它正确打印像这样没有冒号附加:

Which of these styles do you like? 

我试图将所有的文本使用mark_safe通过在此之前为Unicode:

question_3 = forms.MultipleChoiceField(choices=QUESTION_3_CHOICES, 
widget=forms.CheckboxSelectMultiple(), label = mark_safe('Which of 
these styles do you like? (choose multiple)').decode('unicode-escape')) 

但如果问题是没有解决它......

回答

2

“为什么出现这种情况?”然后看看基本形式类的源(在django.forms.forms.BaseForm):

if self.label_suffix: 
    if label[-1] not in ':?.!': 
     label += self.label_suffix 
label = bf.label_tag(label) or '' 

默认情况下,基本形式构造集label_suffix =“:”。

如何解决?尝试在初始化表单时传递label_suffix,很可能它从BaseForm继承。

+0

谢谢 - 修好了! – MikeBrody

相关问题