One seemingly basic thing that I'm having trouble with is rendering a simple list of static files (say the contents of a single repository directory on my server) as a list of links. Whether this is secure or not is another question, but suppose I want to do it... That's how my working directory looks like. And i want to list all the files fro analytics folder in my template, as links.
I have tried accessing static files in view.py following some tutorial and having it like that:
view.py
from os import listdir
from os.path import isfile, join
from django.contrib.staticfiles.templatetags.staticfiles import staticdef AnalyticsView(request):mypath = static('/analytics')allfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]return render_to_response('Rachel/analytics.html', allfiles)
And my template:
<p>ALL FILES:</p>
{% for file in allfiles %}{{ file }}<br>
{% endfor %}
And my settings.py
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static"),
]
And i am getting the error:
FileNotFoundError at /analytics/
[WinError 3] The system cannot find the path specified: '/analytics'
Error traceback Any help will be very appreciated