Search code examples
pythonflaskdeploymentweb-deployment

steps I need to take to make my flask webpage visible by others


I have a webpage with some simple algorithm, which returns the output based on user input & local data file. I checked it's working with my local machine, but found that it doesn't work from my cell phone / other laptops.

I tried several things from web - such as 'python app.py --host=0.0.0.0' on my terminal, or app.run(host='0.0.0.0', port=5000) but didn't work.

I'm trying again from the beginning. below is my code (I named the file app.py), where I put it back to default before any edit.

from flask import Flask,render_template,url_for,request
app = Flask(__name__)
@app.route('/')
def home():
    return render_template('home.html')
@app.route('/predict',methods=['POST'])`
def predict():
#some algorithm stuffs
    return render_template('result.html',  tables=[result.to_html(classes='data',escape=False)], titles=result.columns.values)
if __name__ == '__main__':
    app.run(debug=True)

what should I add on this py file? Also, is there anything beside coding I should do? (firewall, port, etc) I'm currently starting with local machine and planning to work it with virtual machine later (EC2)


Solution

  • If you want to make it visible by anyone you have to open at least one port of your box (depending on your box model you can find some explanations on how to do it), this can be unsafe. You'll then have to map your box port with your PC's port.

    You should go straight with a cloud virtual machine as it's much easier (just allow connexion to the VM port 80)

    A good alternative would be to use Docker and deploy your app on Heroku or Azure (it's free!)

    If you want to make it visible on your own network (just the people on the same WIFI) then it's easier but I don't think that's your point