Made various edits to docs/ref/utils.txt.
This commit is contained in:
parent
8aad4a38ae
commit
beffa061eb
|
@ -16,10 +16,10 @@ the :ref:`internal release deprecation policy <internal-release-deprecation-poli
|
||||||
.. module:: django.utils.cache
|
.. module:: django.utils.cache
|
||||||
:synopsis: Helper functions for controlling caching.
|
:synopsis: Helper functions for controlling caching.
|
||||||
|
|
||||||
This module contains helper functions for controlling caching. It does so by
|
This module contains helper functions for controlling HTTP caching. It does so
|
||||||
managing the ``Vary`` header of responses. It includes functions to patch the
|
by managing the ``Vary`` header of responses. It includes functions to patch
|
||||||
header of response objects directly and decorators that change functions to do
|
the header of response objects directly and decorators that change functions to
|
||||||
that header-patching themselves.
|
do that header-patching themselves.
|
||||||
|
|
||||||
For information on the ``Vary`` header, see :rfc:`7231#section-7.1.4`.
|
For information on the ``Vary`` header, see :rfc:`7231#section-7.1.4`.
|
||||||
|
|
||||||
|
@ -99,10 +99,13 @@ need to distinguish caches by the ``Accept-language`` header.
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
.. module:: django.utils.dateparse
|
.. module:: django.utils.dateparse
|
||||||
:synopsis: Functions to parse datetime objects.
|
:synopsis: Functions to parse strings to datetime objects.
|
||||||
|
|
||||||
The functions defined in this module share the following properties:
|
The functions defined in this module share the following properties:
|
||||||
|
|
||||||
|
- They accept strings in ISO 8601 date/time formats (or some close
|
||||||
|
alternatives) and return objects from the corresponding classes in Python's
|
||||||
|
:mod:`datetime` module.
|
||||||
- They raise :exc:`ValueError` if their input is well formatted but isn't a
|
- They raise :exc:`ValueError` if their input is well formatted but isn't a
|
||||||
valid date or time.
|
valid date or time.
|
||||||
- They return ``None`` if it isn't well formatted at all.
|
- They return ``None`` if it isn't well formatted at all.
|
||||||
|
@ -199,8 +202,8 @@ The functions defined in this module share the following properties:
|
||||||
|
|
||||||
.. function:: smart_text(s, encoding='utf-8', strings_only=False, errors='strict')
|
.. function:: smart_text(s, encoding='utf-8', strings_only=False, errors='strict')
|
||||||
|
|
||||||
Returns a ``str`` object representing ``s``. Treats bytestrings using the
|
Returns a ``str`` object representing arbitrary object ``s``. Treats
|
||||||
``encoding`` codec.
|
bytestrings using the ``encoding`` codec.
|
||||||
|
|
||||||
If ``strings_only`` is ``True``, don't convert (some) non-string-like
|
If ``strings_only`` is ``True``, don't convert (some) non-string-like
|
||||||
objects.
|
objects.
|
||||||
|
@ -222,8 +225,8 @@ The functions defined in this module share the following properties:
|
||||||
|
|
||||||
.. function:: smart_bytes(s, encoding='utf-8', strings_only=False, errors='strict')
|
.. function:: smart_bytes(s, encoding='utf-8', strings_only=False, errors='strict')
|
||||||
|
|
||||||
Returns a bytestring version of ``s``, encoded as specified in
|
Returns a bytestring version of arbitrary object ``s``, encoded as
|
||||||
``encoding``.
|
specified in ``encoding``.
|
||||||
|
|
||||||
If ``strings_only`` is ``True``, don't convert (some) non-string-like
|
If ``strings_only`` is ``True``, don't convert (some) non-string-like
|
||||||
objects.
|
objects.
|
||||||
|
@ -468,7 +471,7 @@ https://web.archive.org/web/20110718035220/http://diveintomark.org/archives/2004
|
||||||
...
|
...
|
||||||
|
|
||||||
Note that as the method is now a property, in Python code it will need to
|
Note that as the method is now a property, in Python code it will need to
|
||||||
be invoked appropriately::
|
be accessed appropriately::
|
||||||
|
|
||||||
# in the view:
|
# in the view:
|
||||||
if person.friends:
|
if person.friends:
|
||||||
|
@ -822,25 +825,27 @@ appropriate entities.
|
||||||
is translated to "persona", the regular expression will match
|
is translated to "persona", the regular expression will match
|
||||||
``persona/(?P<pk>\d+)/$``, e.g. ``persona/5/``.
|
``persona/(?P<pk>\d+)/$``, e.g. ``persona/5/``.
|
||||||
|
|
||||||
.. function:: slugify(allow_unicode=False)
|
.. function:: slugify(value, allow_unicode=False)
|
||||||
|
|
||||||
Converts to ASCII if ``allow_unicode`` is ``False`` (default). Converts spaces to
|
Converts a string to a URL slug by:
|
||||||
hyphens. Removes characters that aren't alphanumerics, underscores, or
|
|
||||||
hyphens. Converts to lowercase. Also strips leading and trailing whitespace.
|
#. Converting to ASCII if ``allow_unicode`` is ``False`` (the default).
|
||||||
|
#. Removing characters that aren't alphanumerics, underscores, hyphens, or
|
||||||
|
whitespace.
|
||||||
|
#. Removing leading and trailing whitespace.
|
||||||
|
#. Converting to lowercase.
|
||||||
|
#. Replacing any whitespace or repeated dashes with single dashes.
|
||||||
|
|
||||||
For example::
|
For example::
|
||||||
|
|
||||||
slugify(value)
|
>>> slugify(' Joel is a slug ')
|
||||||
|
'joel-is-a-slug'
|
||||||
|
|
||||||
If ``value`` is ``"Joel is a slug"``, the output will be
|
If you want to allow Unicode characters, pass ``allow_unicode=True``. For
|
||||||
``"joel-is-a-slug"``.
|
example::
|
||||||
|
|
||||||
You can set the ``allow_unicode`` parameter to ``True``, if you want to
|
>>> slugify('你好 World', allow_unicode=True)
|
||||||
allow Unicode characters::
|
'你好-world'
|
||||||
|
|
||||||
slugify(value, allow_unicode=True)
|
|
||||||
|
|
||||||
If ``value`` is ``"你好 World"``, the output will be ``"你好-world"``.
|
|
||||||
|
|
||||||
.. _time-zone-selection-functions:
|
.. _time-zone-selection-functions:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue