如何使用django表单向导保存文件?

时间:2023-01-14 11:45:25

How to save files using django form wizard? I use Django 1.3 and i can't find examples and solutions. ;-/

如何使用django表单向导保存文件?我使用Django 1.3,我找不到示例和解决方案。 ; - /

With google and django docs i wrote this:

有了google和django docs,我写道:

class ContactWizard(FormWizard):

def done(self, request, form_list):
    d = dict((k, v) for form in form_list for k, v in form.cleaned_data.items())
    d['ip'] = request.META.get('REMOTE_ADDR')
    d['password'] = hashlib.sha1(d['password'])
    db = Ads(**d)
    db.save()
    return HttpResponseRedirect('/')

OK, this save all POST data. But files? I can catch them using request.FILES. I have to save them separately? How to do it best? My form with files is last step in form wizard. I will be grateful for suggestions and examples ;-)

好的,这会保存所有POST数据。但文件?我可以使用request.FILES捕获它们。我要分开保存吗?如何做到最好?我的文件表单是表单向导的最后一步。我将感激建议和例子;-)

1 个解决方案

#1


1  

How about just passing it to Ads as a FileField? So basically, something like this:

如何将其作为FileField传递给Ads?所以基本上,这样的事情:

d['myfile'] = request.FILES['myfile']

#1


1  

How about just passing it to Ads as a FileField? So basically, something like this:

如何将其作为FileField传递给Ads?所以基本上,这样的事情:

d['myfile'] = request.FILES['myfile']