[Fixed]-How to run Django with Uvicorn webserver?

20👍

When not running with the built-in development server, you’ll need to either

👤AKX

6👍

Add below code your settings.py file

STATIC_ROOT = os.path.join(BASE_DIR, 'static', )

Add below code in your urls.py

from django.conf.urls.static import static
from django.conf import settings

urlpatterns = [.
.....] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Then run below command but static directory must exist

python manage.py collectstatic --noinput

start server

uvicorn main.asgi:application --host 0.0.0.0

Leave a comment