Used :envvar: role and .. envvar:: directive in various docs.

This commit is contained in:
Nick Pope 2020-04-30 11:12:05 +01:00 committed by Mariusz Felisiak
parent feb91dbda1
commit fbdb032de2
15 changed files with 65 additions and 49 deletions

View file

@ -118,6 +118,8 @@ mode if you have asynchronous code in your project.
Async safety
============
.. envvar:: DJANGO_ALLOW_ASYNC_UNSAFE
Certain key parts of Django are not able to operate safely in an async
environment, as they have global state that is not coroutine-aware. These parts
of Django are classified as "async-unsafe", and are protected from execution in
@ -144,7 +146,7 @@ if the requirement is forced on you by an external environment, such as in a
Jupyter_ notebook. If you are sure there is no chance of the code being run
concurrently, and you *absolutely* need to run this sync code from an async
context, then you can disable the warning by setting the
``DJANGO_ALLOW_ASYNC_UNSAFE`` environment variable to any value.
:envvar:`DJANGO_ALLOW_ASYNC_UNSAFE` environment variable to any value.
.. warning::

View file

@ -40,10 +40,10 @@ Designating the settings
.. envvar:: DJANGO_SETTINGS_MODULE
When you use Django, you have to tell it which settings you're using. Do this
by using an environment variable, ``DJANGO_SETTINGS_MODULE``.
by using an environment variable, :envvar:`DJANGO_SETTINGS_MODULE`.
The value of ``DJANGO_SETTINGS_MODULE`` should be in Python path syntax, e.g.
``mysite.settings``. Note that the settings module should be on the
The value of :envvar:`DJANGO_SETTINGS_MODULE` should be in Python path syntax,
e.g. ``mysite.settings``. Note that the settings module should be on the
Python `import search path`_.
.. _import search path: https://www.diveinto.org/python3/your-first-python-program.html#importsearchpath
@ -170,10 +170,10 @@ a convention.
.. _settings-without-django-settings-module:
Using settings without setting ``DJANGO_SETTINGS_MODULE``
=========================================================
Using settings without setting :envvar:`DJANGO_SETTINGS_MODULE`
===============================================================
In some cases, you might want to bypass the ``DJANGO_SETTINGS_MODULE``
In some cases, you might want to bypass the :envvar:`DJANGO_SETTINGS_MODULE`
environment variable. For example, if you're using the template system by
itself, you likely don't want to have to set up an environment variable
pointing to a settings module.
@ -234,19 +234,19 @@ defaults, so you must specify a value for every possible setting that might be
used in that code you are importing. Check in
``django.conf.settings.global_settings`` for the full list.
Either ``configure()`` or ``DJANGO_SETTINGS_MODULE`` is required
----------------------------------------------------------------
Either ``configure()`` or :envvar:`DJANGO_SETTINGS_MODULE` is required
----------------------------------------------------------------------
If you're not setting the ``DJANGO_SETTINGS_MODULE`` environment variable, you
*must* call ``configure()`` at some point before using any code that reads
settings.
If you're not setting the :envvar:`DJANGO_SETTINGS_MODULE` environment
variable, you *must* call ``configure()`` at some point before using any code
that reads settings.
If you don't set ``DJANGO_SETTINGS_MODULE`` and don't call ``configure()``,
Django will raise an ``ImportError`` exception the first time a setting
is accessed.
If you don't set :envvar:`DJANGO_SETTINGS_MODULE` and don't call
``configure()``, Django will raise an ``ImportError`` exception the first time
a setting is accessed.
If you set ``DJANGO_SETTINGS_MODULE``, access settings values somehow, *then*
call ``configure()``, Django will raise a ``RuntimeError`` indicating
If you set :envvar:`DJANGO_SETTINGS_MODULE`, access settings values somehow,
*then* call ``configure()``, Django will raise a ``RuntimeError`` indicating
that settings have already been configured. There is a property for this
purpose:
@ -262,7 +262,7 @@ Also, it's an error to call ``configure()`` more than once, or to call
``configure()`` after any setting has been accessed.
It boils down to this: Use exactly one of either ``configure()`` or
``DJANGO_SETTINGS_MODULE``. Not both, and not neither.
:envvar:`DJANGO_SETTINGS_MODULE`. Not both, and not neither.
Calling ``django.setup()`` is required for "standalone" Django usage
--------------------------------------------------------------------