Ticket #11782: 11782.diff

File 11782.diff, 3.4 KB (added by Tim Graham, 15 years ago)

updated patch to apply cleanly to trunk

  • docs/topics/http/file-uploads.txt

     
    99.. versionadded:: 1.0
    1010
    1111When Django handles a file upload, the file data ends up placed in
    12 ``request.FILES`` (for more on the ``request`` object see the documentation for
    13 :ref:`request and response objects <ref-request-response>`). This document
    14 explains how files are stored on disk and in memory, and how to customize the
    15 default behavior.
     12:attr:`request.FILES <django.http.HttpRequest.FILES>` (for more on the
     13``request`` object see the documentation for :ref:`request and response objects
     14<ref-request-response>`). This document explains how files are stored on disk
     15and in memory, and how to customize the default behavior.
    1616
    1717Basic file uploads
    1818==================
    1919
    20 Consider a simple form containing a ``FileField``::
     20Consider a simple form containing a :class:`~django.forms.FileField`::
    2121
    2222    from django import forms
    2323
     
    2525        title = forms.CharField(max_length=50)
    2626        file  = forms.FileField()
    2727
    28 A view handling this form will receive the file data in ``request.FILES``, which
    29 is a dictionary containing a key for each ``FileField`` (or ``ImageField``, or
    30 other ``FileField`` subclass) in the form. So the data from the above form would
     28A view handling this form will receive the file data in
     29:attr:`request.FILES <django.http.HttpRequest.FILES>`, which is a dictionary
     30containing a key for each :class:`~django.forms.FileField` (or
     31:class:`~django.forms.ImageField`, or other :class:`~django.forms.FileField`
     32subclass) in the form. So the data from the above form would
    3133be accessible as ``request.FILES['file']``.
    3234
    33 Note that ``request.FILES`` will only contain data if the request method was
    34 ``POST`` and the ``<form>`` that posted the request has the attribute
    35 ``enctype="multipart/form-data"``. Otherwise, ``request.FILES`` will be empty.
     35Note that :attr:`request.FILES <django.http.HttpRequest.FILES>` will only
     36contain data if the request method was ``POST`` and the ``<form>`` that posted
     37the request has the attribute ``enctype="multipart/form-data"``. Otherwise,
     38``request.FILES`` will be empty.
    3639
    3740Most of the time, you'll simply pass the file data from ``request`` into the
    3841form as described in :ref:`binding-uploaded-files`. This would look
     
    5457            form = UploadFileForm()
    5558        return render_to_response('upload.html', {'form': form})
    5659
    57 Notice that we have to pass ``request.FILES`` into the form's constructor; this
    58 is how file data gets bound into a form.
     60Notice that we have to pass :attr:`request.FILES <django.http.HttpRequest.FILES>`
     61into the form's constructor; this is how file data gets bound into a form.
    5962
    6063Handling uploaded files
    6164-----------------------
    6265
    6366The final piece of the puzzle is handling the actual file data from
    64 ``request.FILES``. Each entry in this dictionary is an ``UploadedFile`` object
    65 -- a simple wrapper around an uploaded file. You'll usually use one of these
    66 methods to access the uploaded content:
     67:attr:`request.FILES <django.http.HttpRequest.FILES>`. Each entry in this
     68dictionary is an ``UploadedFile`` object -- a simple wrapper around an uploaded
     69file. You'll usually use one of these methods to access the uploaded content:
    6770
    6871    ``UploadedFile.read()``
    6972        Read the entire uploaded data from the file. Be careful with this
Back to Top