How to save files using django form wizard?

坚强是说给别人听的谎言 提交于 2019-12-11 14:02:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!