如何配置Django的“静态文件”应用程式列出目录内容? [英] How to configure Django's "staticfiles" app to list directory contents?

查看:881
本文介绍了如何配置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中可用的文件列表/路径/到/静态/目录/ PNG 。相反,我得到404错误目录索引不允许在这里。



现在,如果我直接访问文件,例如 http:// localhost:8000 / static / png / test.png ,它有效。



已经检查了一些答案(此处),但未成功。



所以,有没有人知道如何配置Django,以便 staticfiles 应用程序列出目录内容?

解决方案

 'show_indexes':True 

根据文件


I'm using Django's built-in web server, in DEBUG mode.

This is part of my 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',
)

If I access http://localhost:8000/static/png/, I would expect to see a list of files available in /abs/path/to/static/dir/png. Instead I get a 404 error "Directory indexes are not allowed here."

Now if I access the files directly, e.g. http://localhost:8000/static/png/test.png, it works.

I've already checked some answers (here) without success.

So, does anyone know how to configure Django such that the staticfiles app lists directory contents?

解决方案

'show_indexes': True

As per the documentation

这篇关于如何配置Django的“静态文件”应用程式列出目录内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆