即使我使用Django,也要添加一个glyphicon

时间:2017-11-21 12:26:37

标签: python html django django-forms glyphicons

您好我想知道如何在代码的“输入”左侧添加一个glyphicon,因为我正在使用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)

1 个答案:

答案 0 :(得分:1)

您可以手动渲染字段,而不是渲染整个表单,例如:

<form ...>
    ...
    <i class="glyphicon..."></> {{ form.field_name }}
    ...
</form>

请参阅docs