Reputation: 33624
This is the new project structure (from the Django 1.4 release notes).
myproject |-- manage.py |-- myproject | |-- __init__.py | |-- settings.py | |-- urls.py | `-- wsgi.py `-- polls |-- __init__.py |-- models.py |-- tests.py `-- views.py
What I am not sure about is whether I should point STATIC_ROOT to
myproject/myproject/static/
(together with settings.py, urls.py...)
OR
The top-level directory myproject/static
(next to myproject, myapp1, myapp2)?
Upvotes: 7
Views: 3476
Reputation: 23871
STATIC_ROOT
is not related to Python importing, so it totally depends on you. Normally, myproject/static/
, thus os.path.join(PROJECT_ROOT, 'static/')
in settings, is easier.
update as San4ez suggested, and notes inside settings.py
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
Better to put static files of the poll
app into poll/static/
, according to your structure.
Upvotes: 7
Reputation: 174624
STATIC_ROOT
is just a file path where the staticfiles
contrib app will collect and deposit all static files. It is a location to collect items, that's all. The key thing is that this location is temporary storage and is used mainly when packaging your app for deployment.
The staticfiles
app searches for items to collect from any directory called static
in any apps that are listed in INSTALLED_APPS
and in addition any extra file path locations listed in STATICFILES_DIRS
.
For my projects I create a deploy
directory in which I create a www
folder that I use for static files, and various other files used only when deploying. This directory is at the top level of the project.
You can point the variable to any location to which your user has write permissions, it doesn't need to be in the project directory.
Upvotes: 1
Reputation: 8231
I agree with @okm that myproject/static/
is a good place for static, but also you can store images, css and js inside your app in myproject/polls/media
. Than you have to configure django.contrib.staticfiles
app and copy static from media
to STATIC_ROOT with command
python manage.py collectstatic
The advantage of this approach that this allows you to spread your app with static and your app can be used freely in other projects
Upvotes: 2