【发布时间】:2018-05-04 22:00:38
【问题描述】:
您好,我想知道如何在代码中的“输入”左侧添加一个字形图标,因为我使用的是 django,而且我必须使用 forms.py。
我的 HTML 代码:
<form methode="post" action="/connexion" class="form-horizontal" role="form">
{% csrf_token %}
{{ form.as_p }}
<div>
<button type="submit" class="btn btn-info"><span class="glyphicon glyphicon-off">Connexion</button>
</div>
</form>
forms.py:
class ConnexionForm(forms.Form):
user = forms.CharField(label='', max_length=30, widget=forms.TextInput(attrs={'placeholder': "Nom d'utilisateur"}))
password = forms.CharField(label='', widget=forms.PasswordInput)
【问题讨论】:
-
使用crispy forms。
-
@brunodesthuilliers 谢谢你,但我不明白如何添加字形图标
-
如果您只需要添加图标,请单独渲染每个表单字段并在表单前添加一个 html 元素。喜欢
<i class="glyph..."></i> {{form.name}} ... -
@Beno 如果您知道如何将字形图标添加到手动构建的 html 表单中,那么您使用 django 表单所缺少的只是如何处理表单的渲染以获得所需的html,这就是本文所解释的内容(作为官方文档的补充)。
标签: python html django django-forms glyphicons