我正试图编写代码,使表单数据被发送到后端数据库。表单只是在html
<div class="card-body">
<form class="needs-validation" form action="/elements/forms/add_investor/" novalidate method="post">
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label class="form-label" for="validationCustom01">Investor Name</label>
<input type="text" class="form-control" id="validationCustom01" placeholder="InvestorName" value="MyInvestor" required>
<div class="valid-feedback">
Looks good!
</div>
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="example-url-input" class="form-label">Investor Website</label>
<input class="form-control" type="url" value="https://example.com" id="example-url-input" requried>
<div class="valid-feedback">
Looks good!
</div>
<div class="invalid-feedback">
Please provide a valid web address.
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="mb-3">
<label for="example-url-input" class="form-label">Investor Portfolio</label>
<input class="form-control" type="url" value="https://example.com/portfolio" id="example-url-input" requried>
<div class="invalid-feedback">
Please provide a valid web address.
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="mb-3">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Comments</h4>
<p class="card-title-desc">Please add any comments or notes</p>
</div>
<div class="card-body">
<div id="ckeditor-classic"></div><br>
<button class="btn btn-primary" type="submit">Submit form</button>
</div>
</div>
</div>
</form> <!-- end col -->
</div>
我正在努力理解如何将字段映射到数据库,然后将提交按钮发布到数据库。
我已经通过Django表单部分,但不能映射到这个由于在HTML
中使用不同的元素
我很确定我需要在forms.py
,urls.py
和models.py
中创建这个,但是当我这样做时,如果得到错误。
所以我已经开始新鲜,并希望有人能告诉我我需要什么地图,即使它只是一个字段和提交,那么我可以理解和做剩下的?
代替<form class="needs-validation" form action="/elements/forms/add_investor/" novalidate method="post">
使用<form class="needs-validation" action="whatever_the_function_name_is_in_your views.py_file" novalidate method="post">
另外,给您的字段适当的名称,例如。<input class="form-control" type="url" value="https://example.com/portfolio" id="example-url-input" requried name=Investor_portfolio >
这将帮助每个字段填充数据库电子表格中的正确单元格
观看这个视频(Django中的用户注册(第1部分)- 02:25:55)以更好地理解