Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在烧瓶的卷筒纸中看不到图像_Python_Html_Python 3.x_Web_Flask - Fatal编程技术网

Python 在烧瓶的卷筒纸中看不到图像

Python 在烧瓶的卷筒纸中看不到图像,python,html,python-3.x,web,flask,Python,Html,Python 3.x,Web,Flask,我已经尝试了所有的可能性,但当我点击按钮时,它并没有显示我从本地pc动态拍摄的图像。Is有3到4个应用程序路径,其中有3到4个不同的Html。(一个是bs.Html)。在这里,我有两个模块:一个用于检测身体分割,另一个用于检测脑肿瘤。 app.py bs.html </style> </head> <body bgcolor = "#ffeee6"> <h1><center><u>Radiological Image Cl

我已经尝试了所有的可能性,但当我点击按钮时,它并没有显示我从本地pc动态拍摄的图像。Is有3到4个应用程序路径,其中有3到4个不同的Html。(一个是bs.Html)。在这里,我有两个模块:一个用于检测身体分割,另一个用于检测脑肿瘤。 app.py

bs.html

</style>
</head>
<body bgcolor = "#ffeee6">
 <h1><center><u>Radiological Image Classification</u></center></h1>
 <h2><u>Body Part Segment Detection </u></h2>
 <p><bold>Upload your Radiological image with different body parts: </bold></p> 
 <form action = "/body" method ='POST' enctype=multipart/form-data>
 <input type="file" name="file" >
 <input type="submit"  value="upload" >    
 <h3><u>Results</u></h3> 
 <img src="{{url_for('static',filename = image)}}" align="middle" style="width:150px"/>
 <p>{{data}}</p>
 <p>{{data3}}</p>
 </form>


放射影像分类
人体部位分割检测
上传不同身体部位的放射图像:

结果 {{data}}

{{data3}}


为“bs.html”呈现模板时,传入图像文件名;是否应该改为文件路径,即abc?

指定app.config['UPLOAD\u FOLDER']的相对路径不是一个好主意,因为当前目录不是一个可靠的值。不过,您可以使用相对于python脚本的路径。像这样:

app_dir = os.path.dirname(os.path.abspath(__file__))
app.config['UPLOAD_FOLDER'] = os.path.join(app_dir, 'static')
现在app.config中的路径将始终是脚本文件旁边的静态文件夹

然后做你的事情:

file = request.files['file']
if file:
    filename = secure_filename(file.filename)

    # task 1. let's get a clear path
    path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
    path = os.path.abspath(path)

    # task 2. make sure the folder exists
    folder = os.path.dirname(path)
    if not os.path.isdir(folder):
        raise IOError('no such folder: %s' % folder)

    file.save(path)

    # ... then do template rendering...
    return render_template(...)

顺便说一句,使用
文件
作为变量名是个坏主意。
文件
是python中的内置类型。

UPLOAD\u文件夹
还是静态文件夹?是。它在静态文件夹中
UPLOAD\u FOLDER='./static'
因此主机中的本地路径是
os.path.join(app.config['UPLOAD\u FOLDER'],filename)
。尝试
path=os.path.join(app.config['UPLOAD\u FOLDER',filename)
print(path)
print(os.path.isfile(path))
,查看文件是否已实际保存。还有,你的函数准备做什么?我已经编辑了这个问题。函数prepare用于图像预处理```def prepare(文件):IMG_SIZE=100 IMG_array=cv2.imread(文件,cv2.imread_灰度)IMG_array=IMG_array/255.0 new_array=cv2.resize(IMG_array,(IMG_SIZE,IMG_SIZE))sample_array=new_array.resformate(-1,IMG_SIZE,IMG_SIZE,1)返回样本_arrayTried…但当我们单击提交按钮时,它不会显示图像。我已编辑了我的问题。它显示了相同的问题。图像存储在“静态”文件夹中,但在我们单击“提交”按钮后,它不会显示图像。@SijinJohn右键单击页面以查看源html,获取
标记的src路径。向其添加主机前缀并将其放到浏览器中,例如
http://localhost:8080/static/abc.png
。看看会发生什么
404
或其他什么?@SijinJohn您可能已经知道,但是,某些类型的图像无法在网页中正确显示。像CYMK模式jpg,等等。我们消除了所有可能的原因,然后我们得到了答案。但它只适用于单个模块(例如:身体分割)。如果我们添加3到4个模块,则无法工作。而itz给出的错误是无法访问此站点localhost拒绝连接。尝试:检查连接检查代理和防火墙错误连接_REFUSED@SijinJohn这是一个wsgi应用程序,对吗?添加模块意味着什么?python模块还是烧瓶蓝图?您是否会提供一些应用程序设置代码,以及
app=Flask(…)
file = request.files['file']
if file:
    filename = secure_filename(file.filename)

    # task 1. let's get a clear path
    path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
    path = os.path.abspath(path)

    # task 2. make sure the folder exists
    folder = os.path.dirname(path)
    if not os.path.isdir(folder):
        raise IOError('no such folder: %s' % folder)

    file.save(path)

    # ... then do template rendering...
    return render_template(...)