Browse files

Handle Static and Media Assets

We still lack the CSS required to make our admin interface look nice.
We need to do three things here.

First, we will edit ```` to specify ``STATIC_ROOT``,
``STATIC_URL``, ``MEDIA_ROOT``, and ``MEDIA_URL``. Note that we
decided to put those files in ``/home/dotcloud/data``. By convention,
the ``data`` directory will persist across pushes. This is important:
while you could store static assets in ``/home/dotcloud/current``
(or one of its subdirectories), you probably don't want to store
media (user uploaded files...) in ``current`` or ``code``, because
those directories are wiped out at each push.

The next step is to instruct Nginx to map ``/static`` and ``/media``
to those directories in ``/home/dotcloud/data``. This is done through
a Nginx configuration snippet. You can do many interesting things
with custom Nginx configuration files;
gives some details about that.

The last step is to add the ``collectstatic`` management command to
our ``postinstall`` script. Before calling it, we create the required
directories, just in case.


After pushing this last round of modifications, the CSS for the admin
site (and other static assets) will be found correctly, and we have a
very basic (but functional) Django project to build on!
  • Loading branch information...
1 parent 95c5cf1 commit ee64c91c89b8714125a68669610ac484f30db627 @jpetazzo committed Sep 1, 2011
Showing with 8 additions and 3 deletions.
  1. +3 −3 hellodjango/
  2. +3 −0 nginx.conf
  3. +2 −0 postinstall
@@ -49,18 +49,18 @@
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/"
+MEDIA_ROOT = '/home/dotcloud/data/media/'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "", ""
+MEDIA_URL = '/media/'
# 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/"
+STATIC_ROOT = '/home/dotcloud/data/static/'
# URL prefix for static files.
# Example: ""
@@ -0,0 +1,3 @@
+location /media/ { root /home/dotcloud/data ; }
+location /static/ { root /home/dotcloud/data ; }
@@ -1,3 +1,5 @@
python hellodjango/ syncdb --noinput
+mkdir -p /home/dotcloud/data/media /home/dotcloud/data/static
+python hellodjango/ collectstatic --noinput

0 comments on commit ee64c91

Please sign in to comment.