Я пытаюсь выяснить, почему мои выходные данные заканчивались раньше при перечислении каталогов с моего жесткого диска на веб-сайт. Я удалил сообщение об ошибке для режима отладки и получил эту ошибку:
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\Huang.LabTech2\\Desktop\\Images\\2017 Data\\Air Tractor 402/Air Tractor 402/5-10-2017/IR Filter'
Я не уверен, почему он ищет вторую папку Air Tractor 402 при запуске, но это происходит и с другими папками:
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\Huang.LabTech2\\Desktop\\Images\\2017 Data\\UAV/UAV/Bobby_Hardin/8-16'
Мой код:
from flask import Flask, abort, send_file, render_template, render_template_string
import os
import remoteSensingData
app = Flask(__name__)
@app.route('/', defaults={'req_path': ''})
@app.route('/<path:req_path>')
def dir_listing(req_path):
BASE_DIR = os.path.abspath(r'C:/Users/Huang.LabTech2/Desktop/Images/2017 Data/')
# Joining the base and the requested path
abs_path = os.path.join("c:", BASE_DIR, req_path)
# Return 404 if path doesn't exist
# if not os.path.exists(abs_path):
# return render_template('404.html'), 404
# Check if path is a file and serve
# if os.path.isfile(abs_path):
# return send_file(abs_path)
# Show directory contents
files = os.listdir(abs_path)
files = [os.path.join(req_path, file) for file in files]
# return render_template('files.html', files=files)
return render_template_string("""
<ul>
{% for file in files %}
<li><a href="{{ file }}">{{ file }}</a></li>
{% endfor %}
</ul>
""", files=files)
if __name__ == '__main__':
app.run(debug=True)