2đź‘Ť
In a (correctly configured) production setup, static files are not served by Django but by some frontend server (nginx, apache, whatever), so directory listing is configured on the front server. When working with the builtin dev server, one usually use django’s staticfiles
app to serve the static files. This app doesn’t have any directory listing view but you can easily write one and add it to your urls.py
.
This being said, relying on the front server’s directory listing scanning is brittle at best – you depend on the directory listing being allowed and on the specific server’s implementation. Why don’t you just write a Django view returning a json listing of the directory ? It will take less time than writing the code to “scan” a directory listing and will be much more robust.
0đź‘Ť
in settings.py
STATIC_URL = '/static/'
STATIC_ROOT = PROJECT_DIR + '/static/'
- [Django]-Python logging decorator for views
- [Django]-Running Django on Google Colab
- [Django]-Save() missing 1 required positional argument: 'self' Error while using Django Signal Dispatcher