[英]Django Forms or own html forms?
Is it a good practice to write own forms in django templates isntead of creating built-in django forms? 在django模板中编写自己的表单是创建内置django表单的一种好习惯吗? 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: Django的文档就其在表单创建中的作用发表了以下看法:
source: https://docs.djangoproject.com/en/2.1/topics/forms/ 来源: 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. 作为django及其格式的重度用户。 I recommend django forms with django-crispy-forms.
我建议将django表单与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! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.