Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Django serve list-file
#1
Hello to everyone,
is there some package for Django to list the files in a directory and return a template ready to view them?
I would like to get more or less something like a node's serve-index package for Django.
It would by pretty to create it, but if there is something already ready... so good!!!

Does it exist something like that?

Thank you very much!!
Reply
#2
There is a method for traversing directories in os (import os)
this comes with the python installation
It's named os.walk().
This post has an example: https://python-forum.io/Thread-Automatin...light=walk
Reply
#3
There might be (I didn't see anything while googling, though), but it isn't a super great idea, since Django shouldn't be serving static files.  As Larz points out, it'd be trivial to build yourself using os.walk().

What might not be bad, would be to have a python script that's unrelated to Django, that runs once a day or so on a cron job, that just rebuilds an index.html file based on the current contents of the directory.  That way you've still got an index, it looks however you want, and you don't have to worry about django serving things it shouldn't.
Reply
#4
Thank you very much, the idea is not to serve static file, but to have an interface to view the list in a directory (like serve-index from npm for node).
It should be a template showing the list (i.e UI for a media server, nas etc). I can be created very fastly by hand, but if there is a ready solution is great.
Reply
#5
Even if there's not, serve-index is open source: https://github.com/expressjs/serve-index...ter/public

Copying the css/images/html, and just writing the four lines of python/django glue, should be pretty easy.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Upgraded Django, `AdminSplitDateTime` causes exception on `list` object 1780yz 2 2,943 Feb-24-2021, 04:47 PM
Last Post: 1780yz
  creating an exe file for a python django project Sanjish 0 2,585 Dec-27-2020, 07:33 AM
Last Post: Sanjish
  [Django] css file is not applying to the page SheeppOSU 1 3,029 May-09-2020, 06:54 AM
Last Post: menator01
  upload big file in Django with process bar and i get error : MemoryError ma_norouzifar 3 4,336 Aug-06-2019, 06:57 AM
Last Post: fishhook
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,245 Jun-30-2019, 12:21 AM
Last Post: scidam
  Cannot serve file with send_from_directory nikos 2 2,477 Sep-19-2018, 09:25 PM
Last Post: nikos
  Open Sqlite database file directly in django sourabhjaiswal92 0 2,922 May-22-2018, 05:55 AM
Last Post: sourabhjaiswal92
  How do I make a Django model from a tab-delimited data file? newbietostuff 0 2,500 Jan-09-2018, 02:44 AM
Last Post: newbietostuff
  read text file using python and display its output to html using django amit 0 18,262 Jul-23-2017, 06:14 AM
Last Post: amit

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020