mirror of
https://github.com/django/django.git
synced 2025-01-18 14:24:39 +00:00
Fixed #33757 -- Clarified Client.post() file upload example.
This commit is contained in:
parent
fbac2a4dd8
commit
61badf1d58
@ -241,15 +241,14 @@ Use the ``django.test.Client`` class to make requests.
|
|||||||
|
|
||||||
Submitting files is a special case. To POST a file, you need only
|
Submitting files is a special case. To POST a file, you need only
|
||||||
provide the file field name as a key, and a file handle to the file you
|
provide the file field name as a key, and a file handle to the file you
|
||||||
wish to upload as a value. For example::
|
wish to upload as a value. For example, if your form has fields
|
||||||
|
``name`` and ``attachment``, the latter a
|
||||||
|
:class:`~django.forms.FileField`::
|
||||||
|
|
||||||
>>> c = Client()
|
>>> c = Client()
|
||||||
>>> with open('wishlist.doc', 'rb') as fp:
|
>>> with open('wishlist.doc', 'rb') as fp:
|
||||||
... c.post('/customers/wishes/', {'name': 'fred', 'attachment': fp})
|
... c.post('/customers/wishes/', {'name': 'fred', 'attachment': fp})
|
||||||
|
|
||||||
(The name ``attachment`` here is not relevant; use whatever name your
|
|
||||||
file-processing code expects.)
|
|
||||||
|
|
||||||
You may also provide any file-like object (e.g., :class:`~io.StringIO` or
|
You may also provide any file-like object (e.g., :class:`~io.StringIO` or
|
||||||
:class:`~io.BytesIO`) as a file handle. If you're uploading to an
|
:class:`~io.BytesIO`) as a file handle. If you're uploading to an
|
||||||
:class:`~django.db.models.ImageField`, the object needs a ``name``
|
:class:`~django.db.models.ImageField`, the object needs a ``name``
|
||||||
|
Loading…
x
Reference in New Issue
Block a user