Search code examples
pythonflaskservergunicorn

How set path of folder and files in Gunicorn?


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.


Solution

  • You could try gunicorn's --pythonpath argument:

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