utils.txt 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. ============
  2. Django Utils
  3. ============
  4. .. module:: django.utils
  5. :synopsis: Django's built-in utilities.
  6. This document covers all stable modules in ``django.utils``. Most of the
  7. modules in ``django.utils`` are designed for internal use and only the
  8. following parts can be considered stable and thus backwards compatible as per
  9. the :ref:`internal release deprecation policy <internal-release-deprecation-policy>`.
  10. ``django.utils.cache``
  11. ======================
  12. .. module:: django.utils.cache
  13. :synopsis: Helper functions for controlling caching.
  14. This module contains helper functions for controlling caching. It does so by
  15. managing the ``Vary`` header of responses. It includes functions to patch the
  16. header of response objects directly and decorators that change functions to do
  17. that header-patching themselves.
  18. For information on the ``Vary`` header, see :rfc:`2616#section-14.44` section
  19. 14.44.
  20. Essentially, the ``Vary`` HTTP header defines which headers a cache should take
  21. into account when building its cache key. Requests with the same path but
  22. different header content for headers named in ``Vary`` need to get different
  23. cache keys to prevent delivery of wrong content.
  24. For example, :doc:`internationalization </topics/i18n/index>` middleware would need
  25. to distinguish caches by the ``Accept-language`` header.
  26. .. function:: patch_cache_control(response, **kwargs)
  27. This function patches the ``Cache-Control`` header by adding all keyword
  28. arguments to it. The transformation is as follows:
  29. * All keyword parameter names are turned to lowercase, and underscores
  30. are converted to hyphens.
  31. * If the value of a parameter is ``True`` (exactly ``True``, not just a
  32. true value), only the parameter name is added to the header.
  33. * All other parameters are added with their value, after applying
  34. ``str()`` to it.
  35. .. function:: get_max_age(response)
  36. Returns the max-age from the response Cache-Control header as an integer
  37. (or ``None`` if it wasn't found or wasn't an integer).
  38. .. function:: patch_response_headers(response, cache_timeout=None)
  39. Adds some useful headers to the given ``HttpResponse`` object:
  40. * ``ETag``
  41. * ``Last-Modified``
  42. * ``Expires``
  43. * ``Cache-Control``
  44. Each header is only added if it isn't already set.
  45. ``cache_timeout`` is in seconds. The :setting:`CACHE_MIDDLEWARE_SECONDS`
  46. setting is used by default.
  47. .. function:: add_never_cache_headers(response)
  48. Adds headers to a response to indicate that a page should never be cached.
  49. .. function:: patch_vary_headers(response, newheaders)
  50. Adds (or updates) the ``Vary`` header in the given ``HttpResponse`` object.
  51. ``newheaders`` is a list of header names that should be in ``Vary``.
  52. Existing headers in ``Vary`` aren't removed.
  53. .. function:: get_cache_key(request, key_prefix=None)
  54. Returns a cache key based on the request path. It can be used in the
  55. request phase because it pulls the list of headers to take into account
  56. from the global path registry and uses those to build a cache key to
  57. check against.
  58. If there is no headerlist stored, the page needs to be rebuilt, so this
  59. function returns ``None``.
  60. .. function:: learn_cache_key(request, response, cache_timeout=None, key_prefix=None)
  61. Learns what headers to take into account for some request path from the
  62. response object. It stores those headers in a global path registry so that
  63. later access to that path will know what headers to take into account
  64. without building the response object itself. The headers are named in
  65. the ``Vary`` header of the response, but we want to prevent response
  66. generation.
  67. The list of headers to use for cache key generation is stored in the same
  68. cache as the pages themselves. If the cache ages some data out of the
  69. cache, this just means that we have to build the response once to get at
  70. the Vary header and so at the list of headers to use for the cache key.
  71. ``django.utils.datastructures``
  72. ===============================
  73. .. module:: django.utils.datastructures
  74. :synopsis: Data structures that aren't in Python's standard library.
  75. .. class:: SortedDict
  76. The :class:`django.utils.datastructures.SortedDict` class is a dictionary
  77. that keeps its keys in the order in which they're inserted.
  78. ``SortedDict`` adds two additional methods to the standard Python ``dict``
  79. class:
  80. .. method:: insert(index, key, value)
  81. Inserts the key, value pair before the item with the given index.
  82. .. method:: value_for_index(index)
  83. Returns the value of the item at the given zero-based index.
  84. Creating a new SortedDict
  85. -------------------------
  86. Creating a new ``SortedDict`` must be done in a way where ordering is
  87. guaranteed. For example::
  88. SortedDict({'b': 1, 'a': 2, 'c': 3})
  89. will not work. Passing in a basic Python ``dict`` could produce unreliable
  90. results. Instead do::
  91. SortedDict([('b', 1), ('a', 2), ('c', 3)])
  92. ``django.utils.dateparse``
  93. ==========================
  94. .. versionadded:: 1.4
  95. .. module:: django.utils.dateparse
  96. :synopsis: Functions to parse datetime objects.
  97. The functions defined in this module share the following properties:
  98. - They raise :exc:`ValueError` if their input is well formatted but isn't a
  99. valid date or time.
  100. - They return ``None`` if it isn't well formatted at all.
  101. - They accept up to picosecond resolution in input, but they truncate it to
  102. microseconds, since that's what Python supports.
  103. .. function:: parse_date(value)
  104. Parses a string and returns a :class:`datetime.date`.
  105. .. function:: parse_time(value)
  106. Parses a string and returns a :class:`datetime.time`.
  107. UTC offsets aren't supported; if ``value`` describes one, the result is
  108. ``None``.
  109. .. function:: parse_datetime(value)
  110. Parses a string and returns a :class:`datetime.datetime`.
  111. UTC offsets are supported; if ``value`` describes one, the result's
  112. ``tzinfo`` attribute is a :class:`~django.utils.tzinfo.FixedOffset`
  113. instance.
  114. ``django.utils.encoding``
  115. =========================
  116. .. module:: django.utils.encoding
  117. :synopsis: A series of helper classes and function to manage character encoding.
  118. .. class:: StrAndUnicode
  119. A class whose ``__str__`` returns its ``__unicode__`` as a UTF-8
  120. bytestring. Useful as a mix-in.
  121. .. function:: smart_unicode(s, encoding='utf-8', strings_only=False, errors='strict')
  122. Returns a ``unicode`` object representing ``s``. Treats bytestrings using
  123. the 'encoding' codec.
  124. If ``strings_only`` is ``True``, don't convert (some) non-string-like
  125. objects.
  126. .. function:: is_protected_type(obj)
  127. Determine if the object instance is of a protected type.
  128. Objects of protected types are preserved as-is when passed to
  129. ``force_unicode(strings_only=True)``.
  130. .. function:: force_unicode(s, encoding='utf-8', strings_only=False, errors='strict')
  131. Similar to ``smart_unicode``, except that lazy instances are resolved to
  132. strings, rather than kept as lazy objects.
  133. If ``strings_only`` is ``True``, don't convert (some) non-string-like
  134. objects.
  135. .. function:: smart_str(s, encoding='utf-8', strings_only=False, errors='strict')
  136. Returns a bytestring version of ``s``, encoded as specified in
  137. ``encoding``.
  138. If ``strings_only`` is ``True``, don't convert (some) non-string-like
  139. objects.
  140. .. function:: iri_to_uri(iri)
  141. Convert an Internationalized Resource Identifier (IRI) portion to a URI
  142. portion that is suitable for inclusion in a URL.
  143. This is the algorithm from section 3.1 of :rfc:`3987#section-3.1`. However,
  144. since we are assuming input is either UTF-8 or unicode already, we can
  145. simplify things a little from the full method.
  146. Returns an ASCII string containing the encoded result.
  147. ``django.utils.feedgenerator``
  148. ==============================
  149. .. module:: django.utils.feedgenerator
  150. :synopsis: Syndication feed generation library -- used for generating RSS, etc.
  151. Sample usage::
  152. >>> from django.utils import feedgenerator
  153. >>> feed = feedgenerator.Rss201rev2Feed(
  154. ... title=u"Poynter E-Media Tidbits",
  155. ... link=u"http://www.poynter.org/column.asp?id=31",
  156. ... description=u"A group Weblog by the sharpest minds in online media/journalism/publishing.",
  157. ... language=u"en",
  158. ... )
  159. >>> feed.add_item(
  160. ... title="Hello",
  161. ... link=u"http://www.holovaty.com/test/",
  162. ... description="Testing."
  163. ... )
  164. >>> with open('test.rss', 'w') as fp:
  165. >>> feed.write(fp, 'utf-8')
  166. For simplifying the selection of a generator use ``feedgenerator.DefaultFeed``
  167. which is currently ``Rss201rev2Feed``
  168. For definitions of the different versions of RSS, see:
  169. http://diveintomark.org/archives/2004/02/04/incompatible-rss
  170. .. function:: get_tag_uri(url, date)
  171. Creates a TagURI.
  172. See http://diveintomark.org/archives/2004/05/28/howto-atom-id
  173. SyndicationFeed
  174. ---------------
  175. .. class:: SyndicationFeed
  176. Base class for all syndication feeds. Subclasses should provide write().
  177. .. method:: __init__(title, link, description, [language=None, author_email=None, author_name=None, author_link=None, subtitle=None, categories=None, feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs])
  178. Initialize the feed with the given dictionary of metadata, which applies
  179. to the entire feed.
  180. Any extra keyword arguments you pass to ``__init__`` will be stored in
  181. ``self.feed``.
  182. All parameters should be Unicode objects, except ``categories``, which
  183. should be a sequence of Unicode objects.
  184. .. method:: add_item(title, link, description, [author_email=None, author_name=None, author_link=None, pubdate=None, comments=None, unique_id=None, enclosure=None, categories=(), item_copyright=None, ttl=None, **kwargs])
  185. Adds an item to the feed. All args are expected to be Python ``unicode``
  186. objects except ``pubdate``, which is a ``datetime.datetime`` object, and
  187. ``enclosure``, which is an instance of the ``Enclosure`` class.
  188. .. method:: num_items()
  189. .. method:: root_attributes()
  190. Return extra attributes to place on the root (i.e. feed/channel)
  191. element. Called from ``write()``.
  192. .. method:: add_root_elements(handler)
  193. Add elements in the root (i.e. feed/channel) element.
  194. Called from ``write()``.
  195. .. method:: item_attributes(item)
  196. Return extra attributes to place on each item (i.e. item/entry)
  197. element.
  198. .. method:: add_item_elements(handler, item)
  199. Add elements on each item (i.e. item/entry) element.
  200. .. method:: write(outfile, encoding)
  201. Outputs the feed in the given encoding to ``outfile``, which is a
  202. file-like object. Subclasses should override this.
  203. .. method:: writeString(encoding)
  204. Returns the feed in the given encoding as a string.
  205. .. method:: latest_post_date()
  206. Returns the latest item's ``pubdate``. If none of them have a
  207. ``pubdate``, this returns the current date/time.
  208. Enclosure
  209. ---------
  210. .. class:: Enclosure
  211. Represents an RSS enclosure
  212. RssFeed
  213. -------
  214. .. class:: RssFeed(SyndicationFeed)
  215. Rss201rev2Feed
  216. --------------
  217. .. class:: Rss201rev2Feed(RssFeed)
  218. Spec: http://blogs.law.harvard.edu/tech/rss
  219. RssUserland091Feed
  220. ------------------
  221. .. class:: RssUserland091Feed(RssFeed)
  222. Spec: http://backend.userland.com/rss091
  223. Atom1Feed
  224. ---------
  225. .. class:: Atom1Feed(SyndicationFeed)
  226. Spec: http://www.atomenabled.org/developers/syndication/atom-format-spec.php
  227. ``django.utils.functional``
  228. ===========================
  229. .. module:: django.utils.functional
  230. :synopsis: Functional programming tools.
  231. .. function:: allow_lazy(func, *resultclasses)
  232. Django offers many utility functions (particularly in ``django.utils``) that
  233. take a string as their first argument and do something to that string. These
  234. functions are used by template filters as well as directly in other code.
  235. If you write your own similar functions and deal with translations, you'll
  236. face the problem of what to do when the first argument is a lazy translation
  237. object. You don't want to convert it to a string immediately, because you might
  238. be using this function outside of a view (and hence the current thread's locale
  239. setting will not be correct).
  240. For cases like this, use the ``django.utils.functional.allow_lazy()``
  241. decorator. It modifies the function so that *if* it's called with a lazy
  242. translation as the first argument, the function evaluation is delayed until it
  243. needs to be converted to a string.
  244. For example::
  245. from django.utils.functional import allow_lazy
  246. def fancy_utility_function(s, ...):
  247. # Do some conversion on string 's'
  248. ...
  249. fancy_utility_function = allow_lazy(fancy_utility_function, unicode)
  250. The ``allow_lazy()`` decorator takes, in addition to the function to decorate,
  251. a number of extra arguments (``*args``) specifying the type(s) that the
  252. original function can return. Usually, it's enough to include ``unicode`` here
  253. and ensure that your function returns only Unicode strings.
  254. Using this decorator means you can write your function and assume that the
  255. input is a proper string, then add support for lazy translation objects at the
  256. end.
  257. ``django.utils.http``
  258. =====================
  259. .. module:: django.utils.http
  260. :synopsis: HTTP helper functions. (URL encoding, cookie handling, ...)
  261. .. function:: urlquote(url, safe='/')
  262. A version of Python's ``urllib.quote()`` function that can operate on
  263. unicode strings. The url is first UTF-8 encoded before quoting. The
  264. returned string can safely be used as part of an argument to a subsequent
  265. ``iri_to_uri()`` call without double-quoting occurring. Employs lazy
  266. execution.
  267. .. function:: urlquote_plus(url, safe='')
  268. A version of Python's urllib.quote_plus() function that can operate on
  269. unicode strings. The url is first UTF-8 encoded before quoting. The
  270. returned string can safely be used as part of an argument to a subsequent
  271. ``iri_to_uri()`` call without double-quoting occurring. Employs lazy
  272. execution.
  273. .. function:: urlencode(query, doseq=0)
  274. A version of Python's urllib.urlencode() function that can operate on
  275. unicode strings. The parameters are first case to UTF-8 encoded strings
  276. and then encoded as per normal.
  277. .. function:: cookie_date(epoch_seconds=None)
  278. Formats the time to ensure compatibility with Netscape's cookie standard.
  279. Accepts a floating point number expressed in seconds since the epoch in
  280. UTC--such as that outputted by ``time.time()``. If set to ``None``,
  281. defaults to the current time.
  282. Outputs a string in the format ``Wdy, DD-Mon-YYYY HH:MM:SS GMT``.
  283. .. function:: http_date(epoch_seconds=None)
  284. Formats the time to match the :rfc:`1123` date format as specified by HTTP
  285. :rfc:`2616#section-3.3.1` section 3.3.1.
  286. Accepts a floating point number expressed in seconds since the epoch in
  287. UTC--such as that outputted by ``time.time()``. If set to ``None``,
  288. defaults to the current time.
  289. Outputs a string in the format ``Wdy, DD Mon YYYY HH:MM:SS GMT``.
  290. .. function:: base36_to_int(s)
  291. Converts a base 36 string to an integer.
  292. .. function:: int_to_base36(i)
  293. Converts a positive integer less than sys.maxint to a base 36 string.
  294. ``django.utils.safestring``
  295. ===========================
  296. .. module:: django.utils.safestring
  297. :synopsis: Functions and classes for working with strings that can be displayed safely without further escaping in HTML.
  298. Functions and classes for working with "safe strings": strings that can be
  299. displayed safely without further escaping in HTML. Marking something as a "safe
  300. string" means that the producer of the string has already turned characters
  301. that should not be interpreted by the HTML engine (e.g. '<') into the
  302. appropriate entities.
  303. .. class:: SafeString
  304. A string subclass that has been specifically marked as "safe" (requires no
  305. further escaping) for HTML output purposes.
  306. .. class:: SafeUnicode
  307. A unicode subclass that has been specifically marked as "safe" for HTML
  308. output purposes.
  309. .. function:: mark_safe(s)
  310. Explicitly mark a string as safe for (HTML) output purposes. The returned
  311. object can be used everywhere a string or unicode object is appropriate.
  312. Can be called multiple times on a single string.
  313. .. function:: mark_for_escaping(s)
  314. Explicitly mark a string as requiring HTML escaping upon output. Has no
  315. effect on ``SafeData`` subclasses.
  316. Can be called multiple times on a single string (the resulting escaping is
  317. only applied once).
  318. ``django.utils.translation``
  319. ============================
  320. .. module:: django.utils.translation
  321. :synopsis: Internationalization support.
  322. For a complete discussion on the usage of the following see the
  323. :doc:`translation documentation </topics/i18n/translation>`.
  324. .. function:: gettext(message)
  325. Translates ``message`` and returns it in a UTF-8 bytestring
  326. .. function:: ugettext(message)
  327. Translates ``message`` and returns it in a unicode string
  328. .. function:: pgettext(context, message)
  329. Translates ``message`` given the ``context`` and returns
  330. it in a unicode string.
  331. For more information, see :ref:`contextual-markers`.
  332. .. function:: gettext_lazy(message)
  333. .. function:: ugettext_lazy(message)
  334. .. function:: pgettext_lazy(context, message)
  335. Same as the non-lazy versions above, but using lazy execution.
  336. See :ref:`lazy translations documentation <lazy-translations>`.
  337. .. function:: gettext_noop(message)
  338. .. function:: ugettext_noop(message)
  339. Marks strings for translation but doesn't translate them now. This can be
  340. used to store strings in global variables that should stay in the base
  341. language (because they might be used externally) and will be translated
  342. later.
  343. .. function:: ngettext(singular, plural, number)
  344. Translates ``singular`` and ``plural`` and returns the appropriate string
  345. based on ``number`` in a UTF-8 bytestring.
  346. .. function:: ungettext(singular, plural, number)
  347. Translates ``singular`` and ``plural`` and returns the appropriate string
  348. based on ``number`` in a unicode string.
  349. .. function:: npgettext(context, singular, plural, number)
  350. Translates ``singular`` and ``plural`` and returns the appropriate string
  351. based on ``number`` and the ``context`` in a unicode string.
  352. .. function:: ngettext_lazy(singular, plural, number)
  353. .. function:: ungettext_lazy(singular, plural, number)
  354. .. function:: npgettext_lazy(singular, plural, number)
  355. Same as the non-lazy versions above, but using lazy execution.
  356. See :ref:`lazy translations documentation <lazy-translations>`.
  357. .. function:: string_concat(*strings)
  358. Lazy variant of string concatenation, needed for translations that are
  359. constructed from multiple parts.
  360. .. function:: activate(language)
  361. Fetches the translation object for a given language and installs it as
  362. the current translation object for the current thread.
  363. .. function:: deactivate()
  364. De-installs the currently active translation object so that further _ calls
  365. will resolve against the default translation object, again.
  366. .. function:: deactivate_all()
  367. Makes the active translation object a NullTranslations() instance. This is
  368. useful when we want delayed translations to appear as the original string
  369. for some reason.
  370. .. function:: override(language, deactivate=False)
  371. .. versionadded:: 1.4
  372. A Python context manager that uses
  373. :func:`django.utils.translation.activate` to fetch the translation object
  374. for a given language, installing it as the translation object for the
  375. current thread and reinstall the previous active language on exit.
  376. Optionally it can simply deinstall the temporary translation on exit with
  377. :func:`django.utils.translation.deactivate` if the deactivate argument is
  378. True. If you pass None as the language argument, a NullTranslations()
  379. instance is installed while the context is active.
  380. .. function:: get_language()
  381. Returns the currently selected language code.
  382. .. function:: get_language_bidi()
  383. Returns selected language's BiDi layout:
  384. * ``False`` = left-to-right layout
  385. * ``True`` = right-to-left layout
  386. .. function:: get_language_from_request(request, check_path=False)
  387. .. versionchanged:: 1.4
  388. Analyzes the request to find what language the user wants the system to show.
  389. Only languages listed in settings.LANGUAGES are taken into account. If the user
  390. requests a sublanguage where we have a main language, we send out the main
  391. language.
  392. If ``check_path`` is ``True``, the function first checks the requested URL
  393. for whether its path begins with a language code listed in the
  394. :setting:`LANGUAGES` setting.
  395. .. function:: to_locale(language)
  396. Turns a language name (en-us) into a locale name (en_US).
  397. .. function:: templatize(src)
  398. Turns a Django template into something that is understood by xgettext. It does
  399. so by translating the Django translation tags into standard gettext function
  400. invocations.
  401. .. _time-zone-selection-functions:
  402. ``django.utils.timezone``
  403. =========================
  404. .. versionadded:: 1.4
  405. .. module:: django.utils.timezone
  406. :synopsis: Timezone support.
  407. .. data:: utc
  408. :class:`~datetime.tzinfo` instance that represents UTC.
  409. .. function:: get_default_timezone()
  410. Returns a :class:`~datetime.tzinfo` instance that represents the
  411. :ref:`default time zone <default-current-time-zone>`.
  412. .. function:: get_default_timezone_name()
  413. Returns the name of the :ref:`default time zone
  414. <default-current-time-zone>`.
  415. .. function:: get_current_timezone()
  416. Returns a :class:`~datetime.tzinfo` instance that represents the
  417. :ref:`current time zone <default-current-time-zone>`.
  418. .. function:: get_current_timezone_name()
  419. Returns the name of the :ref:`current time zone
  420. <default-current-time-zone>`.
  421. .. function:: activate(timezone)
  422. Sets the :ref:`current time zone <default-current-time-zone>`. The
  423. ``timezone`` argument must be an instance of a :class:`~datetime.tzinfo`
  424. subclass or, if pytz_ is available, a time zone name.
  425. .. function:: deactivate()
  426. Unsets the :ref:`current time zone <default-current-time-zone>`.
  427. .. function:: override(timezone)
  428. This is a Python context manager that sets the :ref:`current time zone
  429. <default-current-time-zone>` on entry with :func:`activate()`, and restores
  430. the previously active time zone on exit. If the ``timezone`` argument is
  431. ``None``, the :ref:`current time zone <default-current-time-zone>` is unset
  432. on entry with :func:`deactivate()` instead.
  433. .. versionadded:: 1.5
  434. .. function:: localtime(value, timezone=None)
  435. Converts an aware :class:`~datetime.datetime` to a different time zone,
  436. by default the :ref:`current time zone <default-current-time-zone>`.
  437. This function doesn't work on naive datetimes; use :func:`make_aware`
  438. instead.
  439. .. function:: now()
  440. Returns an aware or naive :class:`~datetime.datetime` that represents the
  441. current point in time when :setting:`USE_TZ` is ``True`` or ``False``
  442. respectively.
  443. .. function:: is_aware(value)
  444. Returns ``True`` if ``value`` is aware, ``False`` if it is naive. This
  445. function assumes that ``value`` is a :class:`~datetime.datetime`.
  446. .. function:: is_naive(value)
  447. Returns ``True`` if ``value`` is naive, ``False`` if it is aware. This
  448. function assumes that ``value`` is a :class:`~datetime.datetime`.
  449. .. function:: make_aware(value, timezone)
  450. Returns an aware :class:`~datetime.datetime` that represents the same
  451. point in time as ``value`` in ``timezone``, ``value`` being a naive
  452. :class:`~datetime.datetime`.
  453. This function can raise an exception if ``value`` doesn't exist or is
  454. ambiguous because of DST transitions.
  455. .. function:: make_naive(value, timezone)
  456. Returns an naive :class:`~datetime.datetime` that represents in
  457. ``timezone`` the same point in time as ``value``, ``value`` being an
  458. aware :class:`~datetime.datetime`
  459. .. _pytz: http://pytz.sourceforge.net/
  460. ``django.utils.tzinfo``
  461. =======================
  462. .. module:: django.utils.tzinfo
  463. :synopsis: Implementation of ``tzinfo`` classes for use with ``datetime.datetime``.
  464. .. class:: FixedOffset
  465. Fixed offset in minutes east from UTC.
  466. .. class:: LocalTimezone
  467. Proxy timezone information from time module.