Comment utiliser Django avec Uvicorn¶
Uvicorn est un serveur ASGI basé sur uvloop et httptools, avec un accent sur la vitesse.
Lancement de Django dans Uvicorn¶
Lorsque Uvicorn est installé, une commande uvicorn est disponible qui exécute des applications ASGI. Uvicorn a besoin d’être appelé avec l’emplacement d’un module contenant un objet d’application ASGI, suivi par le nom donné à l’application (séparés par un deux-points).
Pour un projet Django typique, l’invocation de Uvicorn pourrait ressembler à ceci :
python -m uvicorn myproject.asgi:application
Cela démarrera un processus écoutant sur 127.0.0.1: 8000. Il faut que votre projet soit dans le chemin Python ; pour s’en assurer, exécutez cette commande dans le même répertoire que votre fichier manage.py.
In development mode, you can add --reload to cause the server to reload any
time a file is changed on disk.
Pour une utilisation plus avancée, lisez la documentation Uvicorn.
Deploying Django using Uvicorn and Gunicorn¶
Gunicorn is a robust web server that implements process monitoring and automatic restarts. This can be useful when running Uvicorn in a production environment.
To install Uvicorn and Gunicorn, use the following:
python -m pip install uvicorn gunicorn
Then start Gunicorn using the Uvicorn worker class like this:
python -m gunicorn myproject.asgi:application -k uvicorn.workers.UvicornWorker
 
          