mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
MERGED MAGIC-REMOVAL BRANCH TO TRUNK. This change is highly backwards-incompatible. Please read http://code.djangoproject.com/wiki/RemovingTheMagic for upgrade instructions.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@2809 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
d5dbeaa9be
commit
f69cf70ed8
366 changed files with 17833 additions and 11199 deletions
|
@ -31,7 +31,7 @@ How to do it
|
|||
|
||||
Just put this in your URLconf_::
|
||||
|
||||
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/path/to/media'}),
|
||||
(r'^site_media/(.*)$', 'django.views.static.serve', {'document_root': '/path/to/media'}),
|
||||
|
||||
...where ``site_media`` is the URL where your media will be rooted, and
|
||||
``/path/to/media`` is the filesystem root for your media.
|
||||
|
@ -60,7 +60,7 @@ listings for directories.
|
|||
|
||||
Example::
|
||||
|
||||
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/path/to/media', 'show_indexes': True}),
|
||||
(r'^site_media/(.*)$', 'django.views.static.serve', {'document_root': '/path/to/media', 'show_indexes': True}),
|
||||
|
||||
You can customize the index view by creating a template called
|
||||
``static/directory_index``. That template gets two objects in its context:
|
||||
|
@ -100,7 +100,7 @@ Do this by wrapping an ``if DEBUG`` statement around the
|
|||
``django.views.static.serve`` inclusion. Here's a full example URLconf::
|
||||
|
||||
from django.conf.urls.defaults import *
|
||||
from django.conf.settings import DEBUG
|
||||
from django.conf import settings
|
||||
|
||||
urlpatterns = patterns('',
|
||||
(r'^/articles/2003/$', 'news.views.special_case_2003'),
|
||||
|
@ -109,15 +109,15 @@ Do this by wrapping an ``if DEBUG`` statement around the
|
|||
(r'^/articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d+)/$', 'news.views.article_detail'),
|
||||
)
|
||||
|
||||
if DEBUG:
|
||||
if settings.DEBUG:
|
||||
urlpatterns += patterns('',
|
||||
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/path/to/media'}),
|
||||
)
|
||||
|
||||
This code is straightforward. It imports the `DEBUG setting`_ and checks its
|
||||
value. If it evaluates to ``True``, then ``site_media`` will be associated with
|
||||
the ``django.views.static.serve`` view. If not (``DEBUG == False``), then the
|
||||
view won't be made available.
|
||||
This code is straightforward. It imports the settings and checks the value of
|
||||
the ``DEBUG`` setting. If it evaluates to ``True``, then ``site_media`` will be
|
||||
associated with the ``django.views.static.serve`` view. If not
|
||||
(``DEBUG == False``), then the view won't be made available.
|
||||
|
||||
Of course, the catch here is that you'll have to remember to set ``DEBUG=False``
|
||||
in your production settings file. But you should be doing that anyway.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue