-2

I am developing an app in repl.it, when I run the code this is output:

  * Serving Flask app 'main' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

this is my main.py:

from flask import Flask, request, render_template
import subprocess
app = Flask(__name__)

@app.route("/")
def index():
  return render_template('index.html')

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

but I am unable to open 127.0.0.1:5000 and I'm not sure why or how to fix it; would really appreciate any help, thank you

ferg
  • 13
  • 4
  • Do you have access to the server that repl.it runs on? You're trying to access localhost – Sayse Aug 18 '21 at 16:34
  • do you mean the server which my code runs on? – ferg Aug 18 '21 at 16:39
  • Yes, you're running the code in repl.it so their server isn't the same one you're using to try and access localhost on via your web browser – Sayse Aug 18 '21 at 16:40
  • I’m not sure, I presumed the code ran on 127.0.0.1:5000. Sorry I’m not great at all this yet – ferg Aug 18 '21 at 16:46

1 Answers1

2

For running flask in repl.it, make sure you're using their flask template. Afterwards, change your app.run to:

app.run(host="0.0.0.0", port=8080)

And while running, a window should appear with the site above the terminal. You should also be able to access it via https://[project name].[replit username].repl.co

You can see an example here at the bottom: https://replit.com/talk/learn/Flask-Tutorial-Part-1-the-basics/26272

Daniel
  • 61
  • 5