Search code examples
pythonhtmldjangofilefilelist

How to pass directory path from a template to a view?


I'm pretty new to Python\Django.

I'm trying to make a local Netflix-like Library for my Movie\TV shows collection.

The general idea is that the user chooses a media folder, the server side runs on the files in the folder adds them to the database and then the user can search for the items and play them back in the GUI.

The first snag I ran into is getting the folder path from the user without actually uploading any files. After doing some searching online I found this :

<input type="file" id="file_input" webkitdirectory="" directory="">

This HTML code allows the user to choose a folder and iterates through all the files inside, however, I don't know how can I pass this information to views.py so that I could run logic on the input.

Does anyone know how this could be accomplished ?


Solution

  • For security reasons, browsers do not allow to get folder path (Stack Overflow). Since you do not want the user to upload files, the possible solution would be to explicitly mention the folder path in <input type="text">. The simplest solution would be python –m SimpleHTTPServer (source, docs). You may be also interested in this Django app.