问题
How to save files using django form wizard? I use Django 1.3 and i can't find examples and solutions. ;-/
With google and django docs i wrote this:
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 ;-)
回答1:
How about just passing it to Ads as a FileField? So basically, something like this:
d['myfile'] = request.FILES['myfile']
来源:https://stackoverflow.com/questions/7860529/how-to-save-files-using-django-form-wizard