From 0bf5fbfa76544fe921d051619127748ae10237bd Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Mon, 31 Jan 2011 22:06:53 +0000 Subject: Some tweaks to the staticfiles docs to clarify things for new users. Thanks Jannis and brutasse for review and discussion. * Rearranged 'in a nutshell' usage docs to clarify app-dirs vs STATICFILES_DIRS, initially focus on the simplest path to working local dev, and remove the need for repetitive 'you don't need this in local dev' notes. * Added docs on using staticfiles serve view for non-staticfiles (e.g. user-uploaded files). git-svn-id: http://code.djangoproject.com/svn/django/trunk@15380 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/howto/static-files.txt | 106 ++++++++++++++++++--------------------- docs/ref/contrib/staticfiles.txt | 32 +++++++++++- 2 files changed, 79 insertions(+), 59 deletions(-) (limited to 'docs') diff --git a/docs/howto/static-files.txt b/docs/howto/static-files.txt index e5b97403a1..94e04bb738 100644 --- a/docs/howto/static-files.txt +++ b/docs/howto/static-files.txt @@ -7,7 +7,7 @@ Managing static files .. versionadded:: 1.3 Django developers mostly concern themselves with the dynamic parts of web -applications -- the views and templates that render new for each request. But +applications -- the views and templates that render anew for each request. But web applications have other parts: the static files (images, CSS, Javascript, etc.) that are needed to render a complete web page. @@ -38,76 +38,62 @@ Using ``django.contrib.staticfiles`` Here's the basic usage in a nutshell: - 1. Put your static files somewhere that staticfiles will find it. + 1. Put your static files somewhere that ``staticfiles`` will find them. - Most of the time this place will be in a ``static`` directory within - your application, but it could also be a specific directory you've put - into your settings file. See the the documentation for the - :setting:`STATICFILES_DIRS` and :setting:`STATICFILES_FINDERS` settings - for details on where you can put static files. + By default, this means within ``static/`` subdirectories of apps in your + :setting:`INSTALLED_APPS`. - 2. Add some ``staticfiles``-related settings to your settings file. + Many projects will also have static assets that aren't tied to a + particular app; you can give ``staticfiles`` additional directories to + search via the :setting:`STATICFILES_DIRS` setting . - First, you'll need to make sure that ``django.contrib.staticfiles`` - is in your :setting:`INSTALLED_APPS`. + See the documentation for the :setting:`STATICFILES_FINDERS` setting for + details on how ``staticfiles`` finds your files. - Next, you'll need to set the :setting:`STATIC_URL` setting, though - the default value (of ``'/static/'``) is perfect for local development. - See also the :setting:`STATIC_URL` documentation. + 2. Make sure that ``django.contrib.staticfiles`` is in your + :setting:`INSTALLED_APPS`. - Then, edit the :setting:`STATIC_ROOT` setting to point to where - you'd like your static files collected at (when using the - :djadmin:`collectstatic`, see below). For example:: + For :ref:`local development`, if you are using + :ref:`runserver` or adding + :ref:`staticfiles_urlpatterns` to your URLconf, + you're done! Your static files will automatically be served at the + default :setting:`STATIC_URL` of ``/static/``. - STATIC_ROOT = "/home/jacob/projects/mysite.com/sitestatic" - - There are a number of other options available that let you control - *how* static files are stored, where ``staticfiles`` searches for - files, and how files will be served; see :ref:`the staticfiles - settings reference ` for details. - - 3. Run the :djadmin:`collectstatic` management command:: - - ./manage.py collectstatic + 3. You'll probably need to refer to these files in your templates. The + easiest method is to use the included context processor which will allow + template code like: - This'll churn through your static file storage and move them into the - directory given by :setting:`STATIC_ROOT`. + .. code-block:: html+django - .. note:: This is **not necessary in local development** if you are - using :djadmin:`runserver` or adding - ``staticfiles_urlpatterns`` to your URLconf; see below). + .*)$', 'serve', + {'document_root': settings.MEDIA_ROOT}), + ) + +This snippet assumes you've also set your :setting:`MEDIA_URL` (in development) +to ``/media/``. -- cgit v1.3