1. 程式人生 > >django form表單上傳檔案

django form表單上傳檔案

def post(self,request): #表單驗證 form = FilesForm(request.POST or None, request.FILES or None) if form.is_valid(): img = form.cleaned_data['img'] img_detail = form.cleaned_data['img_detail']project_name = request.POST.get('project_name') #專案名 project_desc = request.POST.get('project_desc'
)#專案描述 money = request.POST.get('money')#專案金額 days = request.POST.get('days') #籌集天數 project = Project() project.name = project_name project.money = money project.late_day = days project.remark = project_desc project.status = '0'project.supportmoney = 1000
type = Type(id=1) project.type = type project.img = img project.img_detail = img_detail project.save() return render(request, 'start-step-2.html',{'project_id':project.id})