【发布时间】:2020-09-15 18:32:30
【问题描述】:
我创建了一个 django 网站,医生和患者都可以在其中注册。患者标记他们的问题,它将发送给他/她想要的医生,就像在 Quora 上提问一样。而且我还想将数据保存在db中
但是当患者插入数据时,我的网页没有保存在数据库中。
Models.py
class patients(models.Model):
fever=models.BooleanField()
others=models.TextField()
Views.py
from django.shortcuts import render, redirect
from .models import patients
def patient(request):
if request.method == 'POST':
fever=request.POST['fever']
others=request.POST['others']
patient_details=patients(fever= fever,others = others)
patient_details.save()
return render(request, "patient")
else:
return render(request, "patient.html")
Patient.html
<form action="patient">
<label for="exampleFormControlTextarea1"><u>Mark Your Problems</u></label><br>
<!-- FEVER -->
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="inlineCheckbox1" value="option1">
<label class="form-check-label" name="fever" for="inlineCheckbox1">Fever </label>
</div>
<!--Others-->
<h6 style="text-align:left;"><u>Others</u></h5>
<div class="form-group">
<textarea class="form-control" name="others" id="exampleFormControlTextarea1" rows="1"></textarea>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit"> SUBMIT </button>
</h6>
</form>
我如何将这些数据存储在数据库中?
【问题讨论】:
标签: html django postgresql django-models django-views