mirror of
https://github.com/django/django.git
synced 2025-08-31 07:47:37 +00:00
Used auto-numbered lists in documentation.
This commit is contained in:
parent
cf915cb513
commit
9b15ff08ba
36 changed files with 169 additions and 173 deletions
|
@ -699,12 +699,12 @@ complex conversions between your Python types and your database and
|
|||
serialization formats. Here are a couple of tips to make things go more
|
||||
smoothly:
|
||||
|
||||
1. Look at the existing Django fields (in
|
||||
#. Look at the existing Django fields (in
|
||||
:file:`django/db/models/fields/__init__.py`) for inspiration. Try to find
|
||||
a field that's similar to what you want and extend it a little bit,
|
||||
instead of creating an entirely new field from scratch.
|
||||
|
||||
2. Put a ``__str__()`` method on the class you're wrapping up as a field. There
|
||||
#. Put a ``__str__()`` method on the class you're wrapping up as a field. There
|
||||
are a lot of places where the default behavior of the field code is to call
|
||||
``str()`` on the value. (In our examples in this document, ``value`` would
|
||||
be a ``Hand`` instance, not a ``HandField``). So if your ``__str__()``
|
||||
|
@ -736,12 +736,12 @@ A few suggestions
|
|||
In addition to the above details, there are a few guidelines which can greatly
|
||||
improve the efficiency and readability of the field's code.
|
||||
|
||||
1. The source for Django's own ``ImageField`` (in
|
||||
#. The source for Django's own ``ImageField`` (in
|
||||
``django/db/models/fields/files.py``) is a great example of how to
|
||||
subclass ``FileField`` to support a particular type of file, as it
|
||||
incorporates all of the techniques described above.
|
||||
|
||||
2. Cache file attributes wherever possible. Since files may be stored in
|
||||
#. Cache file attributes wherever possible. Since files may be stored in
|
||||
remote storage systems, retrieving them may cost extra time, or even
|
||||
money, that isn't always necessary. Once a file is retrieved to obtain
|
||||
some data about its content, cache as much of that data as possible to
|
||||
|
|
|
@ -842,13 +842,13 @@ A naive implementation of ``CycleNode`` might look something like this::
|
|||
But, suppose we have two templates rendering the template snippet from above at
|
||||
the same time:
|
||||
|
||||
1. Thread 1 performs its first loop iteration, ``CycleNode.render()``
|
||||
#. Thread 1 performs its first loop iteration, ``CycleNode.render()``
|
||||
returns 'row1'
|
||||
2. Thread 2 performs its first loop iteration, ``CycleNode.render()``
|
||||
#. Thread 2 performs its first loop iteration, ``CycleNode.render()``
|
||||
returns 'row2'
|
||||
3. Thread 1 performs its second loop iteration, ``CycleNode.render()``
|
||||
#. Thread 1 performs its second loop iteration, ``CycleNode.render()``
|
||||
returns 'row1'
|
||||
4. Thread 2 performs its second loop iteration, ``CycleNode.render()``
|
||||
#. Thread 2 performs its second loop iteration, ``CycleNode.render()``
|
||||
returns 'row2'
|
||||
|
||||
The CycleNode is iterating, but it's iterating globally. As far as Thread 1
|
||||
|
|
|
@ -11,14 +11,14 @@ This page describes how you can serve these static files.
|
|||
Configuring static files
|
||||
========================
|
||||
|
||||
1. Make sure that ``django.contrib.staticfiles`` is included in your
|
||||
#. Make sure that ``django.contrib.staticfiles`` is included in your
|
||||
:setting:`INSTALLED_APPS`.
|
||||
|
||||
2. In your settings file, define :setting:`STATIC_URL`, for example::
|
||||
#. In your settings file, define :setting:`STATIC_URL`, for example::
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
3. In your templates, use the :ttag:`static` template tag to build the URL for
|
||||
#. In your templates, use the :ttag:`static` template tag to build the URL for
|
||||
the given relative path using the configured :setting:`STATICFILES_STORAGE`.
|
||||
|
||||
.. _staticfiles-in-templates:
|
||||
|
@ -28,7 +28,7 @@ Configuring static files
|
|||
{% load static %}
|
||||
<img src="{% static "my_app/example.jpg" %}" alt="My image">
|
||||
|
||||
4. Store your static files in a folder called ``static`` in your app. For
|
||||
#. Store your static files in a folder called ``static`` in your app. For
|
||||
example ``my_app/static/my_app/example.jpg``.
|
||||
|
||||
.. admonition:: Serving the files
|
||||
|
@ -159,19 +159,19 @@ Deployment
|
|||
:mod:`django.contrib.staticfiles` provides a convenience management command
|
||||
for gathering static files in a single directory so you can serve them easily.
|
||||
|
||||
1. Set the :setting:`STATIC_ROOT` setting to the directory from which you'd
|
||||
#. Set the :setting:`STATIC_ROOT` setting to the directory from which you'd
|
||||
like to serve these files, for example::
|
||||
|
||||
STATIC_ROOT = "/var/www/example.com/static/"
|
||||
|
||||
2. Run the :djadmin:`collectstatic` management command::
|
||||
#. Run the :djadmin:`collectstatic` management command::
|
||||
|
||||
$ python manage.py collectstatic
|
||||
|
||||
This will copy all files from your static folders into the
|
||||
:setting:`STATIC_ROOT` directory.
|
||||
|
||||
3. Use a web server of your choice to serve the
|
||||
#. Use a web server of your choice to serve the
|
||||
files. :doc:`/howto/static-files/deployment` covers some common deployment
|
||||
strategies for static files.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue