![](/img/trans.png)
[英]Python, print all files in a directory (including those in sub folders)
[英]How to make Django scan all directories including those that are not in static files directory to search media files
我正在嘗試構建一個本地視頻流 web 應用程序,其中Django作為其后端。 我不希望在線托管應用程序,它總是會保留在本地主機中。 現在我面臨的問題是 Django 僅檢測 static 文件目錄中的視頻文件。 但是我不能將所有視頻都放在 static 文件目錄下,因此並非所有文件都可以在 static 文件目錄中(最好我不希望任何視頻文件在其中)。
抱歉,如果我很笨,但是如何讓 Django掃描我的整個系統以查找媒體文件(或者最好只掃描我提供給它的目錄,不一定來自該 web 應用程序的前端)而不將視頻文件放入 ZA81259CEF8E95D32974E 目錄中? 如果不可能,那么我應該如何構建這樣的應用程序?
而且我還注意到來自 HTML 的視頻標簽默認無法播放 x265.mkv 視頻,有沒有辦法讓它們播放它,或者我應該單獨使用其他格式,如 .mp4?
提前致謝。
歡迎來到堆棧溢出(SO):D。 請閱讀https://stackoverflow.com/help/how-to-ask
以下代碼將創建所有文件的列表
file_extensions = ['mp4',...'avi'] # create a list with all file extensions that you want
for f in file_extension: # directory holds the path to the folder in which the search will occur
media_files = [i for i in glob.glob(os.path.join(directory,'*.{}'.format(extension)))]`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.