【发布时间】:2021-09-03 16:01:57
【问题描述】:
<form action="handleAppointment/" method="post" >
{% csrf_token %}
<div class="inputfield">
<label for="doctor" class="label">Doctor</label>
<input type="text" name="doctor" id="doctor" class="input" value={{ doctorName.name }} >
</div>
这是我的表格,我想从数据库中获取完整值。但这里 {{doctorName.name}} 显示的是空格之前的值。
def bookAppointment(request , id ):
doctor = Doctor.objects.filter(id = id ).first()
print(doctor.name)
context = {'doctorName': doctor}
return render(request , 'patient/appointmentForm.html' , context)
运行此代码后,它会在终端中显示“Tapan Shah”作为输出。 这是全名,但它在前端的空格值之前显示“ Tapan ”。
【问题讨论】:
-
在你的 javascript 或数据库中使用 Trim 函数你可以使用 LTRIM、RTRIM 但在 db 级别进行修剪不是一个好主意。
标签: django django-models django-rest-framework django-views django-forms