1👍
✅
There are two ways to accomplish this:
1) Use a third party library, for example django-bootstrap3:
{% load bootstrap3 %}
...
<form class="form-horizontal" name="LoginForm" method="post">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">
{% bootstrap_icon "star" %} Sign In
</button>
{% endbuttons %}
</form>
PS: Don’t forget to add the application bootstrap3
to your INSTALLED_APPS
in settings.py
otherwise it won’t work.
2) Render your form fields manually:
<form class="form-horizontal" name="LoginForm" method="post">
{% csrf_token %}
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">@</span>
<input name="{{ form.username.html_name}}" type="text" class="form-control" placeholder="Username" aria-describedby="basic-addon1">
</div>
...
</form>
Please note that in method (2) you will also need to deal with form and field errors manually. See docs for details.
Source:stackexchange.com