File: troubleshooting.rst

package info (click to toggle)
python-django-channels 4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 872 kB
  • sloc: python: 2,394; makefile: 154; sh: 8
file content (27 lines) | stat: -rw-r--r-- 1,095 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Troubleshooting
===============



ImproperlyConfigured exception
------------------------------


.. code-block:: text

    django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured.
    You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.


This exception occurs when your application tries to import any models before Django finishes
`its initialization process <https://docs.djangoproject.com/en/3.2/ref/applications/#initialization-process>`_ aka ``django.setup()``.


``django.setup()`` `should be called only once <https://docs.djangoproject.com/en/3.2/topics/settings/#calling-django-setup-is-required-for-standalone-django-usage>`_,
and should be called manually only in case of standalone apps.
In context of Channels usage, ``django.setup()`` is called automatically in ``get_asgi_application()``,
which means it needs to be called before any ORM models are imported.

The working code order would look like this:

.. include:: ../includes/asgi_example.rst