【发布时间】:2018-10-28 09:39:15
【问题描述】:
如何在 django 中输入 HTML 表单中的值。我是 django 的新手,正在尝试克隆社交网络。我不确定要为 forms.py、views.py、urls.py 和 models.py 编写什么代码来输入数据。 此外,我还有 html 表单中的各种字段,例如文本框、复选框、单选按钮。 如何将这些字段的数据输入到后端?
html
<form method = 'POST' id = "new_post" action = "/posts/new/">
{% csrf_token %}
<div class="form-group col-md-6">
<label>Title</label><br>
<input type="text" class="form-control" id="inputTitle" placeholder="Enter title">
</div>
<div class="form-group col-md-12">
<label>Situation Description</label><br>
<textarea rows="4" cols="70" class="form-control" placeholder="Enter the situation description"></textarea>
</div>
<div class="form-group col-md-12">
<label>Outcome Description</label><br>
<textarea rows="4" cols="70" class="form-control" placeholder="Enter the outcome description"></textarea>
</div>
<div class="form-group col-md-4">
<label>Outcome Type</label><br>
<select id="inputO_type" class="form-control">
<option>Positive</option>
<option>Neutral</option>
<option>Negative</option>
</select>
</div>
<br>
<div class="form-group col-md-4">
<div class="multiselect">
<div class="selectBox" onclick="showCheckboxes()">
<option>reviewed?</option><select></select>
<div class="overSelect"></div>
</div>
<div id="checkboxes">
<label for="one">
<input type="checkbox" id="one" />Commissioning</label>
<label for="two">
<input type="checkbox" id="two" />Construction</label>
</div>
</div></div>
<div class="form-row">
<br>
<div class="form-group col-md-4">
<label>Tags</label><br>
<select id="inputTag" class="form-control">
<option selected>Algorithms</option>
<option selected>Architecture</option>
<option selected>Automobile</option>
<option>...</option>
</select>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<form method="post" action="#">
<div>
<input type="checkbox" name="FormStuff" id="FormStuff" required>
<label for="FormStuff">Can't find your tag?</label>
<div class="reveal-if-active">
<label for="which-tag">Please fill in your desired tag below</label><br>
<input type="text" id="which-tag" name="which-tag" class="require-if-active" data-require-pair="#choice-tags-typetags">
</div>
<input type="submit" value="Add Tag">
<form method="post" action="#">
</div>
</div>
</div>
<br>
<div class="form-group col-md-4">
<label>Does this warrant a process improvement action?</label>
<div class="form-check">
<input type = "radio" class="form-check-input" value="" class="form-control">
<label>Yes</label>
</div>
<div class="form-check">
<input type = "radio" class="form-check-input" value="" class="form-control">
<label>No</label>
</div>
</div>
</div>
【问题讨论】:
-
你试过Django教程练习吗?
标签: python html django django-forms