如何在枪支中设置文件夹和文件的路径?

发布于 2025-02-13 17:10:19 字数 973 浏览 0 评论 0原文

这是我的烧瓶模块 main.py

import os 
import Flask
import pandas as pd

app = Flask(__name__)

@app.route("/") # this route is working 
def index():
    return "this working"

@app.route("/data", methods=["POST"])
def get_data():
    json = request.json
    df = pd.DataFrame(json)
    #here some other code that work on the data that are geting from folderspath as we have define below 
    
if __name__=="__main__":
    path=os.path.join(os.path.abspath(os.path.join('data')))
    folder=os.path.join(path,'test')
    app.run(debug=Flase,host="0.0.0.0")

如果我们只运行烧瓶服务器,则可以使用path Statment,但是如果我们设置为部署目的并将Gunicorn使用第一个路线工作。但是,当我们将请求发送到第二个路线时,它会在路径中提到缺少文件夹的错误。以下模块(wsgi.py)没有得到那些路径如何设置这些路径,它在wsgi.py

my gunicorn file wsgi.py.py

from main import app
if __name__=="__main__":
    app.run()  
    

我希望wsgi.py在应用程序之前执行这些路径。 run()我试图在app.run()和导入依赖性之前在WSGI中放入这些语句,但仍无法正常工作。

This my flask module main.py

import os 
import Flask
import pandas as pd

app = Flask(__name__)

@app.route("/") # this route is working 
def index():
    return "this working"

@app.route("/data", methods=["POST"])
def get_data():
    json = request.json
    df = pd.DataFrame(json)
    #here some other code that work on the data that are geting from folderspath as we have define below 
    
if __name__=="__main__":
    path=os.path.join(os.path.abspath(os.path.join('data')))
    folder=os.path.join(path,'test')
    app.run(debug=Flase,host="0.0.0.0")

if we just run the flask server it work and execute path statment but if we set for deployment purpose and using gunicorn the first route work. But when we send request to second route it give error of missing folder that are mention in paths. The below module (wsgi.py) is not getting those path how to set these path, that work in wsgi.py

My Gunicorn file wsgi.py

from main import app
if __name__=="__main__":
    app.run()  
    

I want wsgi.py to execute those path before app.run() I tried to put in those statement in wsgi before app.run() and imported dependences but still not working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱人如己 2025-02-20 17:10:20

您可以尝试Gunicorn的-PythonPath论点:

--pythonpath STRING   A comma-separated list of directories to add to the Python path.

You could try gunicorn's --pythonpath argument:

--pythonpath STRING   A comma-separated list of directories to add to the Python path.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文