gpt4 book ai didi

python - Django - While Updating a row in Employee table

转载 作者:行者123 更新时间:2023-11-29 13:06:53 30 4
gpt4 key购买 nike

我在更新员工数据时遇到问题。

我想更新已存在的员工数据。除简历字段外,所有记录均已更新。当我尝试查看数据库时,我发现 FileField:None 但所有其他字段均按预期填充。

我哪里错了?

models.py

class employee_data(models.Model):
eid=models.AutoField(primary_key=True)
f_name=models.CharField(max_length=20)
l_name=models.CharField(max_length=20)
email=models.URLField(unique=True)
username=models.CharField(max_length=30,null=True)
passwd=models.CharField(max_length=30)
location=models.CharField(max_length=30,null=True)
gender=models.CharField(max_length=10,null=True)
mobile=models.CharField(max_length=20,null=True)
jobarea=models.CharField(max_length=30,null=True)
exp=models.CharField(max_length=10,null=True)
current_job=models.CharField(max_length=50,null=True)
skills=models.TextField(null=True)
logincount=models.IntegerField()
resume=models.FileField(upload_to='resume/%Y/%m/%d',null=True)

views.py:

def reg_emp_done(request):
if request.method=='POST':
uid=request.POST['id']
if 'cv' in request.FILES:
form=regform(request.POST,request.FILES)
if form.is_valid:
user=employee_data.objects.get(eid=uid)
user.username=request.POST['uname']
user.location=request.POST['location']
user.gender=request.POST['gender']
user.mobile=request.POST['mob']
user.jobarea=request.POST['jobarea']
user.exp=request.POST['exp']
user.current_job=request.POST['current']
user.skills=request.POST['skills']
user.logincount=user.logincount+1
user.resumefile=request.FILES['cv']
user.save()
return render_to_response('reg_done.html',context_instance=RequestContext(request))
else:
form=regform()
return render_to_response('reg_emp.html',{'msg':'Sorry! Invalid Form','uid':uid},context_instance=RequestContext(request))
else:
form=regform()
return render_to_response('reg_emp.html',{'msg':'Sorry! Resume file is Empty','uid':uid},context_instance=RequestContext(request))
else:
form=regform()
return render_to_response('reg_emp.html',{'msg':'Sorry! Invalid Request, Start over'},context_instance=RequestContext(request))

forms.py:

class regform(forms.Form):
eid=forms.IntegerField()
f_name=forms.CharField(max_length=20)
l_name=forms.CharField(max_length=20)
email=forms.URLField()
username=forms.CharField(max_length=30)
passwd=forms.CharField(max_length=30)
location=forms.CharField(max_length=30)
gender=forms.CharField(max_length=10)
mobile=forms.CharField(max_length=20)
jobarea=forms.CharField(max_length=30)
exp=forms.CharField(max_length=10)
current_job=forms.CharField(max_length=50)
skills=forms.CharField()
logincount=forms.IntegerField()
resume=forms.FileField()

settings.py:

MEDIA_ROOT = '/home/user/Desktop/ojp/media/'

MEDIA_URL = '/media/'

最佳答案

你也可以展示一下你的模板(.html)吗?你把 enctype 添加到你的表单了吗?

form method="POST" enctype="multipart/form-data"

关于python - Django - <FieldFile : None> While Updating a row in Employee table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22578445/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com