Is it a good practice to write own forms in django templates isntead of creating built-in django forms? Like this:
<div class="container">
<div class="row justify-content-center mt-5">
<div class="col-4">
<form method="post" >
{% csrf_token %}
<div class="form-group">
<label for="username">UserName</label><br>
<input type="text" id="username" placeholder="username" name="{{ form.username.name }}"
class="form-control">
</div>
<div class="form-group">
<label for="password1">Password</label><br>
<input type="password" id="password1" placeholder="password"
name="{{ form.password1.name }}" class="form-control">
</div>
<div class="form-group">
<label for="password2">Password</label><br>
<input type="password" id="password2" placeholder="password" name="{{ form.password2.name }}"
class="form-control"> <span id="help"></span>
</div>
<input type="submit" class="btn btn-primary form-control" value="Send">
</form>
</div>
</div>
</div>
Django's docs say the following about their role in form creation:
source: https://docs.djangoproject.com/en/2.1/topics/forms/
If you want to let them do the heavy lifting and manage those three things listed above then why not? No need to re-invent the wheel unless you are doing something that requires it. It really depends on what you're building.
As a heavy user of django and its forms. I recommend django forms with django-crispy-forms. This is the best package you can use to customize a form by functionality and/or layout. They have ready template forms for bootstrap too which I use for most of my projects.
Hope this helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.