| | 53 | |
|---|
| | 54 | Directory listings |
|---|
| | 55 | ================== |
|---|
| | 56 | |
|---|
| | 57 | Optionally, you can pass a ``show_indexes`` parameter to the ``static.serve`` |
|---|
| | 58 | view. This is ``False`` by default. If it's ``True``, Django will display file |
|---|
| | 59 | listings for directories. |
|---|
| | 60 | |
|---|
| | 61 | Example:: |
|---|
| | 62 | |
|---|
| | 63 | (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/path/to/media', 'show_indexes': True}), |
|---|
| | 64 | |
|---|
| | 65 | You can customize the index view by creating a template called |
|---|
| | 66 | ``static/directory_index``. That template gets two objects in its context: |
|---|
| | 67 | |
|---|
| | 68 | * ``directory`` -- the directory name (a string) |
|---|
| | 69 | * ``file_list`` -- a list of file names (as strings) in the directory |
|---|
| | 70 | |
|---|
| | 71 | Here's the default ``static/directory_index`` template:: |
|---|
| | 72 | |
|---|
| | 73 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|---|
| | 74 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
|---|
| | 75 | <head> |
|---|
| | 76 | <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> |
|---|
| | 77 | <meta http-equiv="Content-Language" content="en-us" /> |
|---|
| | 78 | <meta name="robots" content="NONE,NOARCHIVE" /> |
|---|
| | 79 | <title>Index of {{ directory }}</title> |
|---|
| | 80 | </head> |
|---|
| | 81 | <body> |
|---|
| | 82 | <h1>Index of {{ directory }}</h1> |
|---|
| | 83 | <ul> |
|---|
| | 84 | {% for f in file_list %} |
|---|
| | 85 | <li><a href="{{ f }}">{{ f }}</a></li> |
|---|
| | 86 | {% endfor %} |
|---|
| | 87 | </ul> |
|---|
| | 88 | </body> |
|---|
| | 89 | </html> |
|---|