Saturday, October 8, 2011

Re: STATIC_ROOT confusion

Here's what I think is semantically good distinction:

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))   (that's the dir containing your settings.py, that dir is usually one dir below your virtualenv, I simply name it "pr". You can then use PROJECT_ROOT to reference such as:

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static_root')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, 'static/css'),
    os.path.join(PROJECT_ROOT, 'static/img'),
    os.path.join(PROJECT_ROOT, 'static/js'),
)
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

PROJECT_ROOT, "pr" on the filesystem is what you get when you run django-admin.py startproject pr after you run mkvirtualenv foo.com (foo.com would then be the root of your virtualenv; some also call it SITE_ROOT in Django context because they keep web server config, Sass files, etc. there). Here's the dir structure I came to enjoy, also because it maps nicely to the settings posted above:

sa@sub:~/0/2/sr$ type tad2; tad2
tad2 is aliased to `tree  --charset ascii -ad -L 2  -I \.git*\|*\.\~*\|*\.pyc'
.
|-- bin
|-- cache
|-- gems
|   `-- bin
|-- include
|-- lib
|-- log
|-- pid
|-- pkg
|-- pr
|   |-- apps
|   |-- config
|   |-- docs
|   |-- etc -> etcs/development/
|   |-- etcs
|   |-- fixtures
|   |-- formats
|   |-- libs
|   |-- media
|   |-- media_root
|   |-- static
|   |-- static_root
|   |-- templates
|   `-- tests
|-- sass
|-- share
|-- sock
`-- tmp

28 directories
sa@sub:~/0/2/sr$ 


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Xs6NRQ1d-HcJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment