我正在使用Django内置的Web服务器,在DEBUG模式下。
这是我的settings.py的一部分:
如果我访问
现在,如果我直接访问文件,例如
我已经查阅了一些答案(在这里),但没有成功。
那么,有人知道如何配置 Django 使得
这是我的settings.py的一部分:
STATIC_ROOT = '/home/user/static_root'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'/abs/path/to/static/dir',
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
如果我访问
http://localhost:8000/static/png/
,我期望看到的是在 /abs/path/to/static/dir/png
中可用的文件列表。但我得到了一个 404 错误,错误信息为 “Directory indexes are not allowed here.”。现在,如果我直接访问文件,例如
http://localhost:8000/static/png/test.png
,它可以正常工作。我已经查阅了一些答案(在这里),但没有成功。
那么,有人知道如何配置 Django 使得
staticfiles
应用程序可以列出目录内容吗?
static('foo', document_root='/bar', show_indexes=True)
。 - dibery