Bottom Page

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!!
Quote
#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
Quote
#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.
Quote
#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.
Quote
#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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  upload big file in Django with process bar and i get error : MemoryError ma_norouzifar 3 735 Aug-06-2019, 06:57 AM
Last Post: fishhook
  Cannot serve file with send_from_directory nikos 2 664 Sep-19-2018, 09:25 PM
Last Post: nikos
  Open Sqlite database file directly in django sourabhjaiswal92 0 891 May-22-2018, 05:55 AM
Last Post: sourabhjaiswal92
  How do I make a Django model from a tab-delimited data file? newbietostuff 0 809 Jan-09-2018, 02:44 AM
Last Post: newbietostuff
  read text file using python and display its output to html using django amit 0 12,913 Jul-23-2017, 06:14 AM
Last Post: amit

Forum Jump:


Users browsing this thread: 1 Guest(s)