mirror of
https://github.com/django/django.git
synced 2025-05-14 19:06:28 +00:00
Fixed #8224 -- Corrected link in files documentation.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8299 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
4e5aa1b141
commit
12c7918a45
@ -44,7 +44,7 @@ the details of the attached photo::
|
|||||||
u'/media/cars/chevy.jpg'
|
u'/media/cars/chevy.jpg'
|
||||||
>>> car.photo.url
|
>>> car.photo.url
|
||||||
u'http://media.example.com/cars/chevy.jpg'
|
u'http://media.example.com/cars/chevy.jpg'
|
||||||
|
|
||||||
This object -- ``car.photo`` in the example -- is a ``File`` object, which means
|
This object -- ``car.photo`` in the example -- is a ``File`` object, which means
|
||||||
it has all the methods and attributes described below.
|
it has all the methods and attributes described below.
|
||||||
|
|
||||||
@ -61,9 +61,9 @@ Creating ``File`` instances
|
|||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
Most of the time you'll simply use a ``File`` that Django's given you (i.e. a
|
Most of the time you'll simply use a ``File`` that Django's given you (i.e. a
|
||||||
file attached to an model as above, or perhaps an `uploaded file`_).
|
file attached to a model as above, or perhaps an `uploaded file`_).
|
||||||
|
|
||||||
.. _uploaded file: ../uploading_files/
|
.. _uploaded file: ../upload_handling/
|
||||||
|
|
||||||
If you need to construct a ``File`` yourself, the easiest way is to create one
|
If you need to construct a ``File`` yourself, the easiest way is to create one
|
||||||
using a Python built-in ``file`` object::
|
using a Python built-in ``file`` object::
|
||||||
@ -73,9 +73,9 @@ using a Python built-in ``file`` object::
|
|||||||
# Create a Python file object using open()
|
# Create a Python file object using open()
|
||||||
>>> f = open('/tmp/hello.world', 'w')
|
>>> f = open('/tmp/hello.world', 'w')
|
||||||
>>> myfile = File(f)
|
>>> myfile = File(f)
|
||||||
|
|
||||||
Now you can use any of the ``File`` attributes and methods defined below.
|
Now you can use any of the ``File`` attributes and methods defined below.
|
||||||
|
|
||||||
``File`` attributes and methods
|
``File`` attributes and methods
|
||||||
-------------------------------
|
-------------------------------
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ Django's ``File`` has the following attributes and methods:
|
|||||||
``File.path``
|
``File.path``
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
The absolute path to the file's location on a local filesystem.
|
The absolute path to the file's location on a local filesystem.
|
||||||
|
|
||||||
Custom `file storage systems`_ may not store files locally; files stored on
|
Custom `file storage systems`_ may not store files locally; files stored on
|
||||||
these systems will have a ``path`` of ``None``.
|
these systems will have a ``path`` of ``None``.
|
||||||
@ -160,7 +160,7 @@ Additional ``ImageField`` attributes
|
|||||||
``File.width`` and ``File.height``
|
``File.width`` and ``File.height``
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
These attributes provide the dimensions of the image.
|
These attributes provide the dimensions of the image.
|
||||||
|
|
||||||
Additional methods on files attached to objects
|
Additional methods on files attached to objects
|
||||||
-----------------------------------------------
|
-----------------------------------------------
|
||||||
@ -198,7 +198,7 @@ like file systems, opening and reading files, etc.
|
|||||||
|
|
||||||
Django's default file storage is given by the `DEFAULT_FILE_STORAGE setting`_;
|
Django's default file storage is given by the `DEFAULT_FILE_STORAGE setting`_;
|
||||||
if you don't explicitly provide a storage system, this is the one that will be
|
if you don't explicitly provide a storage system, this is the one that will be
|
||||||
used.
|
used.
|
||||||
|
|
||||||
.. _default_file_storage setting: ../settings/#default-file-storage
|
.. _default_file_storage setting: ../settings/#default-file-storage
|
||||||
|
|
||||||
@ -314,17 +314,17 @@ If you need to provide custom file storage -- a common example is storing files
|
|||||||
on some remote system -- you can do so by defining a custom storage class.
|
on some remote system -- you can do so by defining a custom storage class.
|
||||||
You'll need to follow these steps:
|
You'll need to follow these steps:
|
||||||
|
|
||||||
#. Your custom storage system must be a subclass of
|
#. Your custom storage system must be a subclass of
|
||||||
``django.core.files.storage.Storage``::
|
``django.core.files.storage.Storage``::
|
||||||
|
|
||||||
from django.core.files.storage import Storage
|
from django.core.files.storage import Storage
|
||||||
|
|
||||||
class MyStorage(Storage):
|
class MyStorage(Storage):
|
||||||
...
|
...
|
||||||
|
|
||||||
#. Django must be able to instantiate your storage system without any arguments.
|
#. Django must be able to instantiate your storage system without any arguments.
|
||||||
This means that any settings should be taken from ``django.conf.settings``::
|
This means that any settings should be taken from ``django.conf.settings``::
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.files.storage import Storage
|
from django.core.files.storage import Storage
|
||||||
|
|
||||||
@ -336,11 +336,11 @@ You'll need to follow these steps:
|
|||||||
|
|
||||||
#. Your storage class must implement the ``_open()`` and ``_save()`` methods,
|
#. Your storage class must implement the ``_open()`` and ``_save()`` methods,
|
||||||
along with any other methods appropriate to your storage class. See below for
|
along with any other methods appropriate to your storage class. See below for
|
||||||
more on these methods.
|
more on these methods.
|
||||||
|
|
||||||
In addition, if your class provides local file storage, it must override
|
In addition, if your class provides local file storage, it must override
|
||||||
the ``path()`` method.
|
the ``path()`` method.
|
||||||
|
|
||||||
Custom storage system methods
|
Custom storage system methods
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user