热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在Django表单中创建标签粗体?-HowdoImakealabelboldinaDjangoform?

HowcanImakealabelboldinaDjangoform?如何在Django表单中创建标签粗体?Theformelementgoeslikethis:

How can I make a label bold in a Django form?

如何在Django表单中创建标签粗体?

The form element goes like this:

表单元素如下所示:

cOndition= forms.TypedChoiceField(label="My  Condition is",
                              coerce= int,
                              choices=Listed.CONDITION,
                              widget=RadioSelect(attrs={"class": "required"})
                              )

1 个解决方案

#1


8  

Usually, the easiest way would be to do it in your CSS. label[for="id_condition"]{font-weight:bold;} if you're only dealing with browsers that have attribute selectors implemented. These days, that means everything but IE6. If you do need to support IE6, you can wrap the field in a div and style it that way:

通常,最简单的方法是在CSS中执行此操作。 label [for =“id_condition”] {font-weight:bold;}如果您只处理已实现属性选择器的浏览器。这些天,这意味着除IE6之外的一切。如果你确实需要支持IE6,你可以将字段包装在div中并按照这种方式设置样式:

{{ form.condition.label_tag }}{{ form.condition }}

Lastly, if you need to do it on the Python side of things, you can always stick the HTML in your label arg, a-la "My Condition is". But it'll get escaped in the HTML unless you mark it as safe, so you'd end up with:

最后,如果你需要在Python方面做这件事,你可以随时将HTML粘贴在标签arg中,a-la“ My Condition is ”。但它会在HTML中被转义,除非你将它标记为安全,所以你最终得到:

from django.utils.safestring import mark_safe
...
    cOndition= forms.TypedChoiceField(
        label=mark_safe("My Condition is"),
    ...
    )

推荐阅读
author-avatar
施华洛卉子
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有