如何将目录路径从模板传递到视图?

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

我是 Python\Django 的新手。

我正在尝试为我的 Movie\TV 节目集制作一个 local 类似 Netflix 的图书馆。

一般的想法是用户选择一个媒体文件夹,文件夹中文件的服务器端 运行s 将它们添加到数据库中,然后用户可以搜索项目并播放它们在 GUI 中。

我 运行 遇到的第一个障碍是从用户 获取文件夹路径,而 实际上没有上传任何文件。在网上做了一些搜索后,我发现了这个:

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

此 HTML 代码允许用户选择一个文件夹并遍历其中的所有文件,但是,我不知道如何将此信息传递给 views.py 以便我可以运行 输入逻辑。

有谁知道这是如何实现的?

出于安全原因,浏览器不允许获取文件夹路径(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