python - 在 Django 中,我编写了 html 来编辑表单,在通过 value={{ i.full_name}} 从数据库中检索值期间它只显示名字
问题描述
在此处输入图像描述 在此处输入图像描述这是我的 edit.html 代码,在从数据库中检索值并以这种 html 表单显示时,它仅在我写 value={{ i.full_name}} 时显示名字,为什么不完整填写表格时的姓名我已经包含了全名我认为空格后有一些错误它无法再读取字符例如在填写表格时我写了罗文阿特金森但在编辑表格时我只得到罗文。你可以在我附上的图片中看到。
<section class="site-section">
<div class="container">
<div class="row">
<div class="col-lg-12 mb-5">
<h2 class="mb-4 text-center">Update Candidate Details</h2>
<form method="POST" action="/update/ {{i.id}}/" enctype="multipart/form-data" class="p-4 border rounded" onsubmit="myFunction()" >
{% csrf_token %}
{% comment %} <input type="hidden" name="csrfmiddlewaretoken" value="UabxqpD8HGPOu1ZSFnIHAPbMtRgWBAnVHEs8bLDx0HnxN6uhG3LyYvZShvcx1ekn"> {% endcomment %}
<div class="row form-group">
<div class="col-md-12 mb-3 mb-md-0">
<label class="text-black" for="full_name">Full Name :</label>
<input type="text" class="form-control" value ={{ i.full_name}} name="full_name" id="id_full_name" placeholder="Enter First Name">
</div>
</div>
<div class="row form-group">
<div class="col-md-12 mb-3 mb-md-0">
<label class="text-black" for="recruiter_name">Recruiter Name :</label>
<input type="text" class="form-control" value ={{ i.recruiter_name }} name="recruiter_name" id="id_recruiter_name" placeholder="Enter Recruiter Name">
</div>
</div>
{% comment %} <div class="row form-group">
<div class="col-md-12 mb-3 mb-md-0">
<label class="text-black" for="id_last_name">Last Name :</label>
<input type="text" class="form-control" name="last_name" id="id_last_name" placeholder="Enter Last Name">
</div>
</div> {% endcomment %}
<div class="row form-group">
<div class="col-md-12 mb-3 mb-md-0">
<label class="text-black" for="email">Email :</label>
<input type="email" class="form-control" value ={{i.email }} name="email" id="id_email" placeholder="Enter Email">
</div>
</div>
<div class="row form-group">
<div class="col-md-12 mb-3 mb-md-0">
<label class="text-black" for="noticeperiod">Notice Period (in Days) :</label>
<input type="text" class="form-control" value ={{i.noticeperiod }} name="noticeperiod" id="notice_period" placeholder="Notice Period">
</div>
</div>
<div class="row form-group">
<div class="col-md-12 mb-3 mb-md-0">
<label class="text-black" for="preferredlocation">Current Location :</label>
<input type="text" class="form-control" value ={{i.preferredlocation}} name="preferredlocation" id="preferred_location" placeholder="Enter Current Location">
</div>
</div>
<div class="row form-group">
<div class="col-md-12 mb-3 mb-md-0">
<label class="text-black" for="expectedlocation">Expected Location :</label>
<input type="text" class="form-control" value ={{i.expectedlocation}} name="expectedlocation" id="expected_location" placeholder="Enter Multiple Locations seperated by comma">
</div>
</div>
<div class="row form-group">
<div class="col-md-12 mb-3 mb-md-0">
<label class="text-black" for="currentctc">Current CTC (Per Annum) :</label>
<input type="text" class="form-control" value ={{i.currentctc }} name="currentctc" id="current_ctc" placeholder="Current CTC">
</div>
</div>
<div class="row form-group">
<div class="col-md-12 mb-3 mb-md-0">
<label class="text-black" for="expectedctc">Expected CTC (Per Annum) : </label>
<input type="text" class="form-control" value ={{i.expectedctc }} name="expectedctc" id="expected_ctc" placeholder="Expected CTC">
</div>
</div>
<div class="row form-group">
<div class="col-md-12 mb-3 mb-md-0">
<label class="text-black" for="status">Status : </label> </br>
<select name="status" id="status" class="form-control" value ={{i.status }}>
<option value="CV Received">CV Received</option>
<option value="Submitted to Client">Submitted to Client</option>
<option value="Rejected">Rejected</option>
<option value="Offered">Offered</option>
<option value="Joined">Joined</option>
<option value="Closed">Closed</option>
<option value="Payment Received">Payment Received</option>
</select>
{% comment %} <input type="text" class="form-control" name="status" id="status1" placeholder="Enter Application Status"> {% endcomment %}
</div>
</div>
<div class="row form-group">
<div class="col-md-12 mb-3 mb-md-0">
<label class="text-black" >Upload CV</label></br>
<input type="file" name="cv" id="cv1" value ={{ i.cv}} >
</div>
</div>
<div class="row form-group mb-4">
<div class="col-md-12 mb-3 mb-md-0">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="gender" id="male" value={{i.gender}}>
<label class="form-check-label" for="male">Male</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="gender" id="female" value={{i.gender}}>
<label class="form-check-label" for="female">Female</label>
</div>
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<input type="submit" value="Update" id ="submit" class="btn px-4 btn-primary text-white">
{% comment %} <a href="{% url 'jobapp:jobconfirm' %}" class="btn btn-warning btn-block btn-lg">Sign Up</a> {% endcomment %}
</div>
</div>
这是我的意见.py
#delete
def delete(request, id):
i = ApplyForm.objects.get(id = id)
i.delete()
return redirect('account:dboard')
#edit
def edit(request, id):
i = ApplyForm.objects.get(id = id)
context = {
'i' : i
}
return render(request, 'account/edit.html', context)
#update
def update(request, id):
i = ApplyForm.objects.get(id = id)
i.full_name = request.POST['full_name']
i.email = request.POST['email']
i.noticeperiod = request.POST['noticeperiod']
i.preferredlocation = request.POST['preferredlocation']
i.expectedlocation = request.POST['expectedlocation']
i.currentctc = request.POST['currentctc']
i.expectedctc= request.POST['expectedctc']
i.recruiter_name = request.POST['recruiter_name']
i.status = request.POST['status']
i.gender = request.POST['gender']
i.cv = request.FILES['cv']
i.save()
return redirect('account:dboard')
还有我的models.py
class ApplyForm(models.Model):
full_name = models.CharField(max_length=300)
email = models.EmailField(max_length=300)
noticeperiod = models.CharField(max_length = 300)
preferredlocation = models.CharField(max_length=300)
expectedlocation = models.CharField(max_length=300)
currentctc = models.CharField(max_length=300)
expectedctc = models.CharField(max_length=300)
recruiter_name = models.CharField(max_length = 300, null=True)
status = models.CharField(max_length = 300, null=True, choices= CATEGORY_CHOICES )
gender = models.CharField(max_length=10, choices=GENDER_CHOICES)
cv = models.FileField(upload_to='')
这意味着在空格之后我无法检索字符我不知道该怎么做发生了什么我也没有获取选择字段和文件字段的数据,即上传简历、性别、状态字段我从其他字段获取数据但是在任何文本的空格之后,我没有得到我为此附加图像的字符。
解决方案
如果您的问题仍然存在,您可以解决它:
对于“状态”字段:
<select name="status" id="status" class="form-control">
<option value="CV Received"{% if i.status == 'CV Received' %} selected {% endif %}>CV Received</option>
<option value="Submitted to Client"{% if i.status == 'Submitted to Client' %} selected {% endif %}>Submitted to Client</option>
<option value="Rejected"{% if i.status == 'Rejected' %} selected {% endif %}>Rejected</option>
<option value="Offered"{% if i.status == 'Offered' %} selected {% endif %}>Offered</option>
<option value="Joined"{% if i.status == 'Joined' %} selected {% endif %}>Joined</option>
<option value="Closed"{% if i.status == 'Closed' %} selected {% endif %}>Closed</option>
<option value="Payment Received"{% if i.status == 'Payment Received' %} selected {% endif %}>Payment Received</option>
</select>
对于“性别”字段:
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="gender" id="male" value="male" {% if i.gender == 'male' %} checked {% endif %}>
<label class="form-check-label" for="male">Male</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="gender" id="female" value="female" {% if i.gender == 'female' %} checked {% endif %}>
<label class="form-check-label" for="female">Female</label>
</div>
对于上传的简历:
<div class="col-md-12 mb-3 mb-md-0">
{% if i.cv %}
<a href="{{ i.cv.url }}" target="_blank" id="a_link">{{ i.cv }}</a>
{% endif %}
<label class="text-black" >Upload CV</label></br>
<input type="file" name="cv" id="cv1">
</div>
推荐阅读
- javascript - 将附加值添加到定义为数组的 Typescript JSON 键
- c++ - MS Native 单元测试 - 来自线程的 Assert::Fail 不起作用
- javascript - 命令失败:gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
- python - 在 Jenkins 中构建 Docker 映像时如何传递 AWS 凭证?
- xaml - 如何在 xbox 上更改 AppBarButton 的 MediaPlayerElement 样式?
- angular - PrimeNg 日历以角度显示 6 行日期
- odoo - 会不会是破坏odoo系统的原因?
- java - 你能在其他条件语句中使用条件语句吗?
- c# - NoTextEdit ShapeLock 不工作 - OpenXML SDK
- babeljs - 如何从@babel/template 中移除环绕 IIFE?