Folder Setting:
Your project root should look something like this:
/app1 /app2 /media /static /templates urls.py settings.py manage.py
The media folder should store things like images, downloads, and other materials that can be downloaded during normal use of the website (i.e. after development is complete)
The static folder is supposed to store all CSS / JS and other materials that are part of the development site
Settings.py:
MEDIA_ROOT is the absolute path to the above static directory. This means that it should be something like:
MEDIA_ROOT = "/User/Bob/Sites/MySite/Project_root/media/"
MEDIA_URL is the relative URL of the browser with which you must access the media files when you look at the site. It should be (usually)
MEDIA_URL = "media/"
which means that all materials can be viewed at http://example.com/media/
Similarly, STATIC_ROOT should be something like
STATIC_ROOT = "/User/Bob/Sites/MySite/Project_root/static/"
and STATIC_URL be
STATIC_URL = "static/"
File service:
Now that you have told django where these folders should be and the correct URLs to access them, you need to properly handle all folder requests.
Usually, when you are in production, you want the web server to take care of the maintenance of your static files and media files.
If you are developing, you can simply start the django development server to serve them.
To do this, you will tell him to forward the entire request that is included in http://example.com/media to your MEDIA_ROOT and all requests that are included in http://example.com/static to your STATIC_ROOT.
To do this, you add some URLS to URLS.py, as you:
from django.conf import settings if settings.DEBUG: urlpatterns += patterns('', url(r'^media/(?P<path>.*)$', 'django.views.static.serve', { 'document_root': settings.MEDIA_ROOT, }), url(r'^static/(?P<path>.*)$', 'django.views.static.serve', { 'document_root': settings.STATIC_ROOT, }), )
Extra
If you have several applications, each with its own CSS and JS files, you may not want to drop them into one / static / folder. It might be useful to place them in the subfolders of the applications to which they belong:
/app1/static/ # Specific static folder /app2/static/ /media/ /static/ # Root static folder
Now your webserver / development server is only looking for static files in which you told it to look (i.e. the root static folder), so you need to collect all the files in subfolders and copy them to the root static folder. You can do it manually, but django provides a command for this for you (this is the whole point of a static application)
./manage collectstatic