2
def get_path():
imgs = []
for img in os.listdir('/Users/MYUSERNAME/Desktop/app/static/imgs/'):
imgs.append(img)
image = random.randint(0, len(imgs)-1) #gen random image path from images in directory
return imgs[image].split(".")[0] #get filename without extension
@app.route("/blahblah")
def show_blah():
img = get_path()
return render_template('blahblah.html', img=img) #template just shows image
我想要做的是不必使用操作系統獲取文件,除非有辦法使用燒瓶方法。我知道這種方式只適用於我的電腦,而不是我嘗試上傳的任何服務器。如何列出Flask靜態子目錄中的所有圖像文件?