1👍
✅
Read this Django_Docs
You must also have a STATIC_ROOT
option set before you can use the static files, heres some help
add this to your code:
STATIC_URL = os.path.join(PROJECT_ROOT, 'static').replace('\\','')+'/'
# Here you can add all the directories from where you want to use your js, css etc
STATICFILES_DIRS = [
# This can be same as the static url
os.path.join(PROJECT_ROOT, "static"),
# also any other dir you wanna use
"/any/other/static/path/you/wanna/use",
]
# This is the static root dir from where django uses the files from.
STATIC_ROOT = os.path.join(PROJECT_ROOT, "static_root")
you will also need to specify it in the urls.py
file, just add the following code to the urls.py
file:
from django.conf import settings
from django.conf.urls.static import static
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
after you add this, run the command:
python manage.py collectstatic
This will copy all the statics you need to the static root dir.
Source:stackexchange.com