1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #14524, #14582, #14617, #14665 and #14667 -- Tweaked staticfiles app.

* Updated StaticFilesHandler and AdminMediaHandler
  to make use of the 404 handler if needed.

* Updated runserver management command to serve static files
  only in DEBUG mode (or if specified the --insecure option)
  and if the staticfiles app is in INSTALLED_APPS. Also added
  an option to disable serving completely (--nostatic).

* Added check in debug mode if STATICFILES_* settings are
  different to MEDIA_* settings.

* Removed a faulty PendingDeprecationWarning in AdminMediaHandler
  that is triggered every time runserver is used.

* Fixed an issue with the modification time checks when
  running collectstatic.

* Extended and refined documentation.

Thanks to everyone for input, especially to Carl Meyer, Ted Kaemming and
Adam Vandenberg for patches.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14533 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel
2010-11-11 21:43:49 +00:00
parent 216fdfab61
commit 8e96584f63
14 changed files with 190 additions and 78 deletions

View File

@@ -37,7 +37,7 @@ Using ``django.contrib.staticfiles``
Here's the basic usage in a nutshell:
1. Put your media somewhere that staticfiles will find it..
1. Put your media somewhere that staticfiles will find it.
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
@@ -69,12 +69,19 @@ Here's the basic usage in a nutshell:
./manage.py collectstatic
This'll churn through your static file storage and move them into the
directory given by :setting:`STATICFILES_ROOT`.
directory given by :setting:`STATICFILES_ROOT`. (This is not necessary
in local development if you are using :djadmin:`runserver` or adding
``staticfiles_urlpatterns`` to your URLconf; see below).
4. Deploy that media.
If you're using the built-in development server, you can quickly
serve static media locally by adding::
If you're using the built-in development server (the
:djadmin:`runserver` management command) and have the :setting:`DEBUG`
setting set to ``True``, your staticfiles will automatically be served
from :setting:`STATICFILES_URL` in development.
If you are using some other server for local development, you can
quickly serve static media locally by adding::
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns()
@@ -100,6 +107,18 @@ Those are the basics. For more details on common configuration options, read on;
for a detailed reference of the settings, commands, and other bits included with
the framework see :doc:`the staticfiles reference </ref/contrib/staticfiles>`.
.. note::
In previous versions of Django, it was common to place static assets in
:setting:`MEDIA_ROOT` along with user-uploaded files, and serve them both at
:setting:`MEDIA_URL`. Part of the purpose of introducing the ``staticfiles``
app is to make it easier to keep static files separate from user-uploaded
files. For this reason, you will probably want to make your
:setting:`MEDIA_ROOT` and :setting:`MEDIA_URL` different from your
:setting:`STATICFILES_ROOT` and :setting:`STATICFILES_URL`. You will need to
arrange for serving of files in :setting:`MEDIA_ROOT` yourself;
``staticfiles`` does not deal with user-uploaded media at all.
.. _staticfiles-in-templates:
Referring to static files in templates
@@ -192,8 +211,12 @@ media server, which is a lot of overhead to mess with when developing locally.
Thus, the ``staticfiles`` app ships with a quick and dirty helper view that you
can use to serve files locally in development.
To enable this view, you'll add a couple of lines to your URLconf. The first
line goes at the top of the file, and the last line at the bottom::
This view is automatically enabled and will serve your static files at
:setting:`STATICFILES_URL` when you use the built-in :djadmin:`runserver`.
To enable this view if you are using some other server for local development,
you'll add a couple of lines to your URLconf. The first line goes at the top of
the file, and the last line at the bottom::
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
@@ -242,7 +265,7 @@ app, the basic outline gets modified to look something like:
* On the server, run :djadmin:`collectstatic` to move all the media into
:setting:`STATICFILES_ROOT`.
* Point your web server at :setting:`STATICFILES_ROOT`. For example, here's
of :ref:`how to do this under Apache and mod_wsgi <serving-media-files>`.
:ref:`how to do this under Apache and mod_wsgi <serving-media-files>`.
You'll probably want to automate this process, especially if you've got multiple
web servers. There's any number of ways to do this automation, but one option
@@ -393,6 +416,10 @@ you'll need to make a few changes:
``staticfiles.storage.StaticFileStorage`` to
``staticfiles.storage.StaticFilesStorage``
* If using :djadmin:`runserver` for local development (and the
:setting:`DEBUG` setting is ``True``), you no longer need to add
anything to your URLconf for serving static files in development.
Learn more
==========