I am confused by static root and I want to clarify the situation.
To serve static files in Django, the urls.py should be specified in settings.py and urls.py :
import os PROJECT_DIR=os.path.dirname(__file__)
1. The absolute path to the directory where 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 places for static files
STATICFILES_DIRS = ( os.path.join(PROJECT_DIR,'static/'),)
... and in urls.py 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:
Can someone explain to me the workflow: how everything should be ideal. At the moment, I copy / paste the above code snippets to their designated places and continue to create new files in the static directory, and it works. However, in my settings.STATIC_ROOT I pointed to a different directory.
It would be great if someone could explain the workflow of each parameter: how the files are assembled and managed, and what would be good practice.
Thank.
django django-urls django-staticfiles
user993563 Dec 31 '11 at 11:49 2011-12-31 11:49
source share