Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.6.x] Fixed #20973 -- Document serving static files without django.…

…contrib.staticfiles

Backport of 7b04038 from master
  • Loading branch information...
commit a62b640f7d3a0b90c4009cc7efe0a19fd3ad0bfa 1 parent 2a14c08
Loic Bistuer authored September 01, 2013 timgraham committed September 03, 2013
9  docs/howto/deployment/wsgi/modwsgi.txt
@@ -173,10 +173,11 @@ will be served using mod_wsgi::
173 173
 Serving the admin files
174 174
 =======================
175 175
 
176  
-Note that the Django development server automatically serves the static files
177  
-of the admin app (and any other installed apps), but this is not the case when
178  
-you use any other server arrangement. You're responsible for setting up Apache,
179  
-or whichever media server you're using, to serve the admin files.
  176
+When :mod:`django.contrib.staticfiles` is in :setting:`INSTALLED_APPS`, the
  177
+Django development server automatically serves the static files of the
  178
+admin app (and any other installed apps). This is however not the case when you
  179
+use any other server arrangement. You're responsible for setting up Apache, or
  180
+whichever Web server you're using, to serve the admin files.
180 181
 
181 182
 The admin files live in (:file:`django/contrib/admin/static/admin`) of the
182 183
 Django distribution.
52  docs/howto/static-files/index.txt
@@ -40,9 +40,9 @@ Configuring static files
40 40
     In addition to these configuration steps, you'll also need to actually
41 41
     serve the static files.
42 42
 
43  
-    During development, this will be done automatically if you use
44  
-    :djadmin:`runserver` and :setting:`DEBUG` is set to ``True`` (see
45  
-    :func:`django.contrib.staticfiles.views.serve`).
  43
+    During development, if you use :mod:`django.contrib.staticfiles`, this will
  44
+    be done automatically by :djadmin:`runserver` when :setting:`DEBUG` is set
  45
+    to ``True`` (see :func:`django.contrib.staticfiles.views.serve`).
46 46
 
47 47
     This method is **grossly inefficient** and probably **insecure**,
48 48
     so it is **unsuitable for production**.
@@ -76,15 +76,49 @@ details on how ``staticfiles`` finds your files.
76 76
     application itself.
77 77
 
78 78
 
79  
-Serving files uploaded by a user
80  
-================================
  79
+Serving static files during development.
  80
+========================================
  81
+
  82
+If you use :mod:`django.contrib.staticfiles` as explained above,
  83
+:djadmin:`runserver` will do this automatically when :setting:`DEBUG` is set
  84
+to ``True``. If you don't have ``django.contrib.staticfiles`` in
  85
+:setting:`INSTALLED_APPS`, you can still manually serve static files using the
  86
+:func:`django.contrib.staticfiles.views.serve` view.
  87
+
  88
+This is not suitable for production use! For some common deployment
  89
+strategies, see :doc:`/howto/static-files/deployment`.
  90
+
  91
+For example, if your :setting:`STATIC_URL` is defined as ``/static/``, you can do
  92
+this by adding the following snippet to your urls.py::
  93
+
  94
+    from django.conf import settings
  95
+    from django.conf.urls.static import static
  96
+
  97
+    urlpatterns = patterns('',
  98
+        # ... the rest of your URLconf goes here ...
  99
+    ) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
  100
+
  101
+.. note::
  102
+
  103
+    This helper function works only in debug mode and only if
  104
+    the given prefix is local (e.g. ``/static/``) and not a URL (e.g.
  105
+    ``http://static.example.com/``).
  106
+
  107
+    Also this helper function only serves the actual :setting:`STATIC_ROOT`
  108
+    folder; it doesn't perform static files discovery like
  109
+    `:mod:`django.contrib.staticfiles`.
  110
+
  111
+Serving files uploaded by a user during development.
  112
+====================================================
81 113
 
82 114
 During development, you can serve user-uploaded media files from
83 115
 :setting:`MEDIA_ROOT` using the :func:`django.contrib.staticfiles.views.serve`
84  
-view. This is not suitable for production use! For some common deployment
  116
+view.
  117
+
  118
+This is not suitable for production use! For some common deployment
85 119
 strategies, see :doc:`/howto/static-files/deployment`.
86 120
 
87  
-For example, if your :setting:`MEDIA_URL` is defined as '/media/', you can do
  121
+For example, if your :setting:`MEDIA_URL` is defined as ``/media/``, you can do
88 122
 this by adding the following snippet to your urls.py::
89 123
 
90 124
     from django.conf import settings
@@ -97,8 +131,8 @@ this by adding the following snippet to your urls.py::
97 131
 .. note::
98 132
 
99 133
     This helper function works only in debug mode and only if
100  
-    the given prefix is local (e.g. ``/static/``) and not a URL (e.g.
101  
-    ``http://static.example.com/``).
  134
+    the given prefix is local (e.g. ``/media/``) and not a URL (e.g.
  135
+    ``http://media.example.com/``).
102 136
 
103 137
 Deployment
104 138
 ==========
13  docs/ref/settings.txt
@@ -1411,6 +1411,14 @@ Example: ``"/var/www/example.com/media/"``
1411 1411
 
1412 1412
 See also :setting:`MEDIA_URL`.
1413 1413
 
  1414
+.. warning::
  1415
+
  1416
+    :setting:`MEDIA_ROOT` and :setting:`STATIC_ROOT` must have different
  1417
+    values. Before :setting:`STATIC_ROOT` was introduced, it was common to
  1418
+    rely or fallback on :setting:`MEDIA_ROOT` to also serve static files;
  1419
+    however, since this can have serious security implications, there is a
  1420
+    validation check to prevent it.
  1421
+
1414 1422
 .. setting:: MEDIA_URL
1415 1423
 
1416 1424
 MEDIA_URL
@@ -1424,6 +1432,11 @@ to a non-empty value.
1424 1432
 
1425 1433
 Example: ``"http://media.example.com/"``
1426 1434
 
  1435
+.. warning::
  1436
+
  1437
+    :setting:`MEDIA_URL` and :setting:`STATIC_URL` must have different
  1438
+    values. See :setting:`MEDIA_ROOT` for more details.
  1439
+
1427 1440
 .. setting:: MIDDLEWARE_CLASSES
1428 1441
 
1429 1442
 MIDDLEWARE_CLASSES

0 notes on commit a62b640

Please sign in to comment.
Something went wrong with that request. Please try again.