#428 closed enhancement (fixed)
[patch] view for serving static files
Reported by: | Owned by: | Jacob | |
---|---|---|---|
Component: | Generic views | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It would be nice to be able to serve static files from disk while using the test django server. This can be done with a view and urlpattern.
I've hacked up an implementation at: http://django.pastebin.com/347411
To use it, put that in your view directory (say in static.py), then add
DOCUMENT_ROOT = '/your/local/document/root/dir'
to your settings file, and a pattern:
(r'^(?P<path>.*)$', 'foo.apps.foo.views.static.serve')
at the end of your urlpatterns list. This will pick up all the URLs that all the previous patterns couldn't match and try to find them under DOCUMENT_ROOT.
Is there any interest in adding this view to the other views django already provides?
Attachments (2)
Change History (7)
by , 19 years ago
by , 19 years ago
Attachment: | static_view.patch added |
---|
Static file view in the form of a patch against django trunk
comment:1 by , 19 years ago
Summary: | view for serving static files → [patch] view for serving static files |
---|
Resubmitted static file view in the form of a patch. DOCUMENT_ROOT is still the same, but now your URL handler would look something like:
urlpatterns = patterns('', # Other patterns here (r'^(?P<path>.*)$', 'django.views.static.serve') # This should be last )
comment:3 by , 19 years ago
priority: | low → normal |
---|---|
Severity: | minor → normal |
This is seems to be a really common request on IRC. Probably more than just low priority.
comment:4 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:5 by , 19 years ago
There's a typo in the URL pattern example (an extraneous `)')
Index: django/views/static.py =================================================================== --- django/views/static.py (revision 699) +++ django/views/static.py (working copy) @@ -13,7 +13,7 @@ To use, put a URL pattern like:: - (r'^(?P<path>).*)$', 'django.views.static.serve', {'document_root' : '/path/to/my/files/'}) + (r'^(?P<path>.*)$', 'django.views.static.serve', {'document_root' : '/path/to/my/files/'}) in your URL conf; you must provide the ``document_root`` param. You may also set ``show_indexes`` to ``True`` if you'd like to serve a basic index
static file view