Merge pull request #291 from jazzband/feature/asgi

This commit is contained in:
Brian Helba 2021-10-25 09:49:54 -04:00 committed by GitHub
commit df51535afc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 3 deletions

View file

@ -81,7 +81,7 @@ command line option, e.g.
python manage.py runserver --settings=mysite.settings --configuration=Dev
To enable Django to use your configuration you now have to modify your
**manage.py** or **wsgi.py** script to use django-configurations's versions
**manage.py**, **wsgi.py** or **asgi.py** script to use django-configurations's versions
of the appropriate starter functions, e.g. a typical **manage.py** using
django-configurations would look like this:
@ -120,5 +120,18 @@ The same applies to your **wsgi.py** file, e.g.:
Here we don't use the default ``django.core.wsgi.get_wsgi_application``
function but instead ``configurations.wsgi.get_wsgi_application``.
Or if you are not serving your app via WSGI but ASGI instead, you need to modify your **asgi.py** file too.:
.. code-block:: python
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
os.environ.setdefault('DJANGO_CONFIGURATION', 'DEV')
from configurations.asgi import get_asgi_application
application = get_asgi_application()
That's it! You can now use your project with ``manage.py`` and your favorite
WSGI enabled server.
WSGI/ASGI enabled server.

8
configurations/asgi.py Normal file
View file

@ -0,0 +1,8 @@
from . import importer
importer.install()
from django.core.asgi import get_asgi_application # noqa: E402
# this is just for the crazy ones
application = get_asgi_application()

View file

@ -182,7 +182,7 @@ probably just add the following to the **beginning** of your settings module:
import configurations
configurations.setup()
That has the same effect as using the ``manage.py`` or ``wsgi.py`` utilities.
That has the same effect as using the ``manage.py``, ``wsgi.py`` or ``asgi.py`` utilities.
This will also call ``django.setup()``.
>= 3.1