1

Django を使用して複数のファイルをアップロードしようとしています。次のコードを使用して、html 形式で複数のファイルを選択します。 index.html

IMAGE Files:<input type="file" name="image" multiple /><br/>

Views.py

image=request.FILES.get('image')

models.py

image=models.ImageField(upload_to=get_upload_pathimage)

これで、最後のファイルのみが取得されます (3 つのファイルを選択すると、3 番目のファイルが取得されます)。すべての画像を取得するには?

4

3 に答える 3

1

request.FILES is a MultiValueDict and doing get will return only the last value as you noted. If you want all of the values you should use images = request.FILES.getlist('image').

于 2013-08-15T18:07:06.127 に答える