我刚刚开始尝试使用 flask 我正在尝试列出使用它的网络驱动程序。这是我在浏览器上输入的命令。但我得到一个错误,它找不到路径 http://127.0.0.1:5000/130.13.5.8/D/dir/
该功能适用于本地驱动程序,没有问题
我知道为什么失败了。它需要在实际 ip 之前有 2 个 '\' 或 4 个 '\\' 。 但是当我尝试 http://127.0.0.1:5000/////130.13.5.8/D/dir/ 它不起作用。 我什至尝试过 %F%F 它似乎也不起作用。
@app.route('/<path:filepath>/dir/')
def get_dir(filepath):
dir_listing = ''
for entry in os.listdir(filepath):
entry_type = 'dir' if os.path.isdir(os.path.join(filepath, entry)) else 'file'
dir_listing += '{entry_name}|{entry_type}|'.format(entry_name=entry, entry_type=entry_type)
return dir_listing
最佳答案
对于遇到同样问题的人,我的解决方法如下
from ipaddress import ip_address
try:
ip_address(filepath.split('/')[0])
filepath = '\\\\{filepath}'.format(filepath=filepath)
except ValueError as e:
pass
关于python - Flask系统找不到指定的路径: '130.127.5.9' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57223875/