7

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)?

1
  • 3
    I don't know what the "official" word is, but I think the top level directory makes more sense. Commented Apr 16, 2012 at 4:38

3 Answers 3

7

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

1 Comment

css, js, and images should all be subfolders in myproject/myproject/static, as well as myproject/poll/static. Using a folder named media is dangerous because it conflicts with the folder name typically used in django for images and other files uploaded by users. It's also a folder used by admin static files (after collectstatic). Collect static will indeed gather them up for a production server to then serve them from a central folder (usually outside your myproject folder structure, like /var/www/www.mysite.com/static).
1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.