20👍
✅
When not running with the built-in development server, you’ll need to either
- use whitenoise which does this as a Django/WSGI middleware (my recommendation)
-
use the classic staticfile deployment procedure which collects all static files into some root and a static file server is expected to serve them. Uvicorn doesn’t seem to support static file serving, so you might need something else too (see e.g. https://www.uvicorn.org/deployment/#running-behind-nginx).
-
(very, very unpreferably!) have Django serve static files like it does in dev
👤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
- Apache2 and context path for virtual host with Django and AngularJS
- Django DB level default value for a column
Source:stackexchange.com