[Django] #34143: Multiple file upload docs

2 views
Skip to first unread message

Django

unread,
Nov 6, 2022, 11:19:15 AM11/6/22
to django-...@googlegroups.com
#34143: Multiple file upload docs
----------------------------------------------+------------------------
Reporter: Guillaume LEBRETON | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 4.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------------+------------------------
In the docs, https://docs.djangoproject.com/en/dev/topics/http/file-
uploads/#uploading-multiple-files
there is this code snippet:

{{{
def post(self, request, *args, **kwargs):
form_class = self.get_form_class()
form = self.get_form(form_class)
files = request.FILES.getlist('file_field')
if form.is_valid():
for f in files:
... # Do something with each file.
return self.form_valid(form)
else:
return self.form_invalid(form)
}}}
I think it's a bit confusing to use form validation and then get the file
list directly from the request.
I found that replacing {{{ files = request.FILES.getlist('file_field') }}}
by {{{ files = form.files.getlist('file_field') }}} seems to be more
consistent with the usual django form approach.

The best approach would be to access {{{ file_field }}} from cleaned_data
but it's not really possible with multple files for now.

--
Ticket URL: <https://code.djangoproject.com/ticket/34143>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 6, 2022, 11:22:08 AM11/6/22
to django-...@googlegroups.com
#34143: Multiple file upload docs
-------------------------------------+-------------------------------------
Reporter: Guillaume LEBRETON | Owner: Guillaume
| LEBRETON
Type: Uncategorized | Status: assigned
Component: Uncategorized | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Guillaume LEBRETON):

* owner: nobody => Guillaume LEBRETON
* status: new => assigned
* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/34143#comment:1>

Django

unread,
Nov 6, 2022, 11:47:35 AM11/6/22
to django-...@googlegroups.com
#34143: Multiple file upload docs
-------------------------------------+-------------------------------------
Reporter: Guillaume LEBRETON | Owner: Guillaume
| LEBRETON
Type: Uncategorized | Status: assigned
Component: Uncategorized | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Guillaume LEBRETON:

Old description:

> In the docs, https://docs.djangoproject.com/en/dev/topics/http/file-
> uploads/#uploading-multiple-files
> there is this code snippet:
>
> {{{
> def post(self, request, *args, **kwargs):
> form_class = self.get_form_class()
> form = self.get_form(form_class)
> files = request.FILES.getlist('file_field')
> if form.is_valid():
> for f in files:
> ... # Do something with each file.
> return self.form_valid(form)
> else:
> return self.form_invalid(form)
> }}}
> I think it's a bit confusing to use form validation and then get the file
> list directly from the request.
> I found that replacing {{{ files = request.FILES.getlist('file_field')
> }}} by {{{ files = form.files.getlist('file_field') }}} seems to be more
> consistent with the usual django form approach.
>
> The best approach would be to access {{{ file_field }}} from cleaned_data
> but it's not really possible with multple files for now.

New description:

In the docs, https://docs.djangoproject.com/en/dev/topics/http/file-
uploads/#uploading-multiple-files
there is this code snippet:

{{{
def post(self, request, *args, **kwargs):
form_class = self.get_form_class()
form = self.get_form(form_class)
files = request.FILES.getlist('file_field')
if form.is_valid():
for f in files:
... # Do something with each file.
return self.form_valid(form)
else:
return self.form_invalid(form)
}}}
I think it's a bit confusing to use form validation and then get the file
list directly from the request.
I found that replacing {{{ files = request.FILES.getlist('file_field') }}}
by {{{ files = form.files.getlist('file_field') }}} seems to be more
consistent with the usual django form approach.

The best approach would be to access {{{ file_field }}} from cleaned_data
but it's not really possible with multple files for now.

PR link: https://github.com/django/django/pull/16265

--

--
Ticket URL: <https://code.djangoproject.com/ticket/34143#comment:2>

Django

unread,
Nov 7, 2022, 3:57:22 AM11/7/22
to django-...@googlegroups.com
#34143: Multiple file upload docs
-------------------------------------+-------------------------------------
Reporter: Guillaume LEBRETON | Owner: Guillaume
| LEBRETON
Type: Uncategorized | Status: closed
Component: Documentation | Version: 4.1
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: assigned => closed
* resolution: => invalid
* component: Uncategorized => Documentation


Comment:

Thanks for this patch, however ''"​Uploading multiple files"'' contains
only a simple example how you can handle multiple files (see related
#31710). Moreover `Form.files` is an undocumented API.

--
Ticket URL: <https://code.djangoproject.com/ticket/34143#comment:3>

Reply all
Reply to author
Forward
0 new messages