mirror of
https://github.com/django/django.git
synced 2025-11-02 04:48:33 +00:00
Fixes #15270 -- Moved back the serve view to django.views.static due to dependency conflicts with the contrib app staticfiles (reverts parts of r14293). Added a helper function that generates URL patterns for serving static and media files during development. Thanks to Carl for reviewing the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15530 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
6b1191b1a2
commit
a26034ffbf
8 changed files with 223 additions and 211 deletions
|
|
@ -317,31 +317,3 @@ already defined pattern list. Use it like this::
|
|||
This helper function will only work if :setting:`DEBUG` is ``True``
|
||||
and your :setting:`STATIC_URL` setting is neither empty nor a full
|
||||
URL such as ``http://static.example.com/``.
|
||||
|
||||
.. _staticfiles-serve-other-directories:
|
||||
|
||||
Serving other directories
|
||||
"""""""""""""""""""""""""
|
||||
|
||||
There may be files other than your project's static assets that, for
|
||||
convenience, you'd like to have Django serve for you in local development. The
|
||||
:func:`~django.contrib.staticfiles.views.serve` view can be used to serve any
|
||||
directory you give it. (Again, this view is **not** hardened for production
|
||||
use, and should be used only as a development aid; you should serve these files
|
||||
in production using a real front-end webserver).
|
||||
|
||||
The most likely example is user-uploaded content in :setting:`MEDIA_ROOT`.
|
||||
``staticfiles`` is intended for static assets and has no built-in handling for
|
||||
user-uploaded files, but you can have Django serve your :setting:`MEDIA_ROOT`
|
||||
by appending something like this to your URLconf::
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns += patterns('django.contrib.staticfiles.views',
|
||||
url(r'^media/(?P<path>.*)$', 'serve',
|
||||
{'document_root': settings.MEDIA_ROOT}),
|
||||
)
|
||||
|
||||
This snippet assumes you've also set your :setting:`MEDIA_URL` (in development)
|
||||
to ``/media/``.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue