I am confused by static root and want to clarify things.
To serve static files in Django, the following should be in settings.py and urls.py:
import os
PROJECT_DIR=os.path.dirname(__file__)
1. Absolute path to the directory in which static files should be collected
STATIC_ROOT= os.path.join(PROJECT_DIR,'static_media/')
2. URL prefix for static files
STATIC_URL = '/static/'
3. Additional locations for static files
STATICFILES_DIRS = ( os.path.join(PROJECT_DIR,'static/'),)
...and in urls.py the following lines:
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += patterns('', (
r'^static/(?P<path>.*)$',
'django.views.static.serve',
{'document_root': settings.STATIC_ROOT}
))
4. We also use python manage.py collectstatic
Questions:
Could anyone please explain the workflow to me: how should things ideally be done. As of now, I copy/paste the above code snippets into their designated locations and continue making new files in the static directory and it works. In my
settings.STATIC_ROOT, however, I have pointed to a different directory.It would be great if someone could explain the workflow of each setting: how files are collected and managed, and what would be a good practice to follow.
Thanks.
if settings.DEBUG:django is not very good at serving static media, this should be left to a real webserver. - dm03514