omar mkhlalati
omar mkhlalati

Reputation: 11

Cant run flask on ngrok

from flask import Flask, escape, request

app = Flask(__name__)
run_with_ngrok()
@app.route('/')
def hello():
   name = request.args.get("name", "World")
   return f'Hello, {escape(name)}!'

When I run the this from terminal with "flask run" it doesn't print an ngrok link. Im i an virtual env and i have tried running it with python "file name" and it did not work.

Upvotes: 1

Views: 4851

Answers (4)

On your phone you need set access point (AP/hotspot) ON.

Upvotes: 0

Makati Dhruvi
Makati Dhruvi

Reputation: 1

from flask_ngrok import run_with_ngrok
from flask import Flask, escape, request

app = Flask(__name__)
app.secret_key = '33d5f499c564155e5d2795f5b6f8c5f6'
run_with_ngrok(app)
@app.route('/')
def hello():
   name = request.args.get("name", "World")
   return f'Hello, {escape(name)}!'

if __name__ == "__main__":
app.run(debug=True)

We can grab token from ngrok.com website by signin

In terminal we need to run like

ngrok config add-authtoken <your_token>
ngrok http 5000

for flask it is 5000 and for other application it would be different

And we also need to run our application side by side

Upvotes: 0

Surya R
Surya R

Reputation: 475

if you are trying to expose your ip through ngrok, you can try tunneling with ngrok on terminal for the flask app's port

your app code should look like :

from flask import Flask, escape, request

app = Flask(__name__)

@app.route('/')
def hello():
   name = request.args.get("name", "World")
   return f'Hello, {escape(name)}!'
   
   
if __name__ == "__main__":
   app.run(port=5000)

you can tunnel the flask app port with the following command:

ngrok http 5000

here the port 5000 denotes the flask app port.

Upvotes: 3

Mohammad
Mohammad

Reputation: 46

I think you forgot to add this part to end of your file

if __name__ == "__main__":
   app.run()

Upvotes: 0

Related Questions