As described there, I tried
{{{#!python
with open('mal.csv', 'rb') as fp:
self.client.post('/post/endpoint/', {'name': 'fred', 'attachment': fp})
}}}
And assumed that (as described there)
> The name attachment here is not relevant; use whatever name your file-
processing code expects.
This made the test fail. Printing request.FILES returned:
`<MultiValueDict: {'attachment': [<InMemoryUploadedFile: mal.csv
(text/csv)>]}>`
What worked was the (way more intuitive)
{{{#!python
with open('mal.csv', 'rb') as fp:
self.client.post('/post/entpoint/', {'name': 'fred', 'attachment': fp})
# <MultiValueDict: {'fred': [<InMemoryUploadedFile: mal.csv (text/csv)>]}>
}}}
I did not check:
* since when the documentation is obsolete
* if this is intended behavior
--
Ticket URL: <https://code.djangoproject.com/ticket/33757>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => invalid
Comment:
Thanks for the report, however it works for me, see also
[https://github.com/django/django/blob/d5bc36203057627f6f7d0c6dc97b31adde6f4313/tests/file_uploads/tests.py#L86-L93
tests].
> What worked was the (way more intuitive) ...
This snippet is exactly the same as the version you think is not working
🤔
If you're having trouble understanding how Django works, see
TicketClosingReasons/UseSupportChannels for ways to get help.
--
Ticket URL: <https://code.djangoproject.com/ticket/33757#comment:1>
Comment (by Tim Graham):
The example in the documentation initializes a client `c = Client()` while
the snippet here uses `self.client`. It might that the latter version has
some state attached to it (like a login) which makes the difference, but
it's impossible to debug without some minimal example code. Please include
that in future reports (and first confirm a bug in Django using support
channels).
--
Ticket URL: <https://code.djangoproject.com/ticket/33757#comment:2>