sean Oops ... must be in the top 10 of the Django FAQ.
To create a separate static app seems like the right thing for a website with photos etc.
But just to deliver a CSS file and a favicon that is probably overkill.
I chose instead to let Django handle this small task:
My static files are in proj/app/static
, so that is what I added in STATICFILES_DIRS
in settings.py:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'app', 'static') ]
python manage.py collectstatic
creates the assets folder. (I created it locally, and then copied it to the server.)
proj/proj/urls.py must be changed. These imports are needed:
from django.urls import re_path
from django.views.static import serve
from django.conf import settings
And this must be added to urlpatterns
:
re_path(
r'^static/(?P<path>.*)$',
serve,
{'document_root': settings.STATIC_ROOT}
)
Works as expected 🙂
https://old-brainball.watchduck.net/w1,y13,w3,w9,y5,y4,y8,y7,y6,w2,y12,y11,w10