37,718
社区成员
发帖
与我相关
我的任务
分享
# views.py
import os
from django.conf import settings
from django.shortcuts import render
def list_all_img(request):
img_list = []
for static_path in settings.STATICFILES_DIRS:
img_list.extend(os.listdir(os.path.join(static_path, 'images'))
return render(request,'app_path/list_all_img.html', {'img_list': img_list}
# list_all_img.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>display</title>
</head>
<body>
{% for img in img_list: %}
<br/><img src="/static/images/{{ img }}">
{% endfor %}
</body>
</html>