如何使用django表单向导保存文件? [英] How to save files using django form wizard?
问题描述
如何使用django表单向导保存文件?我使用Django 1.3,我找不到示例和解决方案。 ; - /
How to save files using django form wizard? I use Django 1.3 and i can't find examples and solutions. ;-/
使用google和django文档我写了:
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('/')
确定,这将保存所有POST数据。但文件?我可以使用request.FILES抓住他们。我要分开保存吗?怎么做最好?我的表单与文件是表单向导的最后一步。
我将不胜感激的建议和例子; - )
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 ;-)
推荐答案
一个href =https://docs.djangoproject.com/en/1.3/ref/models/fields/#django.db.models.FileField =nofollow> FileField ?所以基本上是这样的:
How about just passing it to Ads as a FileField? So basically, something like this:
d['myfile'] = request.FILES['myfile']
这篇关于如何使用django表单向导保存文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!