首页 > 解决方案 > how do I set an app path to get the image I upload on flask?

问题描述

I am working on a flask project and having a hard time getting the image I uploaded.

appPath = os.path.join(os.path.curdir, 'app')

trnsourceRoot = os.path.join(appPath, 'static/trnsource')

this is in my index.py




websvr

+trnsvr
|
\--trn_db.py

+app
|
\--main
   |
   --index.py

\--static
   |
   --trnsource

I checked where does my file upload on

C:\mirae\facnroll_aws_210215\app\static\trnsource\F21021701\M21021700

but I am getting a 404 error when the image is loaded on the web.

how do I solve this? If need more information, please ask me further questions to clarify.

Thanks ahead.

标签: pythonflaskpathsrc

解决方案


I found that actually the path when I upload the picture was misleading and I fixed it by running python on the right path.

in index.py

I had appPath = os.path.join(os.path.curdir, 'app') and it set the current python directory as the appPath.

Originally

original path python was executed the python was executed on the path above.

On the visual code terminal, I had to do cd websvr which is the subfolder.

enter image description here

I did python run.py and it resolved the problem.


推荐阅读