1.前台
上传身份证照片
个人手持身份证照片
{% csrf_token %}
2.后台
def writerApply(request):try:
loginbean= request.session[‘loginbean‘]if loginbean==None:return HttpResponse("")if request.method != ‘POST‘:return render(request, ‘home/writerApply.html‘)else:
dict=request.POST.dict()
del dict[‘csrfmiddlewaretoken‘]
idimage= request.FILES.get(‘idimage‘)if idimage ==None:return HttpResponse(‘必须上传身份证照片‘)
exit(0)
idperson= request.FILES.get(‘idperson‘)if idperson ==None:return HttpResponse(‘必须上传手持身份证照片‘)
exit(0)try:
#改图片名字另存为
idimagePath= "%s1%s"%(time.time(),idimage.name)
f= open(os.path.join("manager\\static\\imgs",idimagePath), ‘wb‘)for chunk in idimage.chunks(chunk_size=1024):
f.write(chunk)
dict[‘idimage‘] =idimagePath
idpersonPath= "%s2%s" %(time.time(), idperson.name)
f= open(os.path.join("manager\\static\\imgs",idpersonPath), ‘wb‘)for chunk in idperson.chunks(chunk_size=1024):
f.write(chunk)
dict[‘idperson‘] =idpersonPath
writer= Writers.objects.create(createtime=time.strftime(‘%Y-%m-%d %H:%M:%S‘, time.localtime(time.time())), **dict)
print(writer)
except Exceptionase:
print(e)finally:
f.close()return HttpResponse(‘上传成功‘)
#入库操作
# print(dict)
# realname= request.POST.get(‘realname‘)
#return HttpResponse(dict[‘realname‘])
#writer= Writers.objects.create(createtime=time.strftime(‘%Y-%m-%d %H:%M:%S‘, time.localtime(time.time())),**dict) # **dict必须放到最后
except Exceptionaserr:
print(err)return HttpResponse("")