作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在更新员工数据时遇到问题。
我想更新已存在的员工数据。除简历字段外,所有记录均已更新。当我尝试查看数据库时,我发现 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/
我是一名优秀的程序员,十分优秀!