Flask app not loading except when deployed

Question:
I am coding a Flask application that runs perfectly fine when deployed using Replit Deployments but does not run within Replit.

This means that in order to see and interact with my app, I need to redeploy it each time. It’s a huge slowdown when trying to build new features.

Has anyone else experienced/fixed this?

Hi @JakeOShea , welcome to the forums!

You can give a link to your repl so that we can find the cause of the problem (it is important that the repl is not private).

When you launch a Flask application (not deployed), does it return an error, or does it not even start?

Thanks @KAlexK. I’m nervous about sharing the full Repl but I’ll put a smaller one here. It’s not even starting, but in the console it says the program is running - essentially it’s just not loading the webpage.

Here’s a link to a repl that is basially the exact same minus functions, here’s what happens when I try to run it.

https://replit.com/@JakeOShea/ShowerDebug#main.py

To run your Flask application, you use debug mode. The debug mode does not work in Replit, so it does not need to be enabled when the application is launched.

I’m not understanding? I removed Debug mode from my code and it is still not loading unless I deploy the project. Why won’t it let me run the code locally on the virtual machine?

Hey @JakeOShea!

I forked your Repl to see if it runs at all, but I’m not able to get it to output a website. Is there any extra configuration required for it to run such as missing environment variables?

Edit: Uploaded the screenshot

@ShaneAtReplit: If you remove debug=True from app.run, it should open a site. If it does not, then that is the issue this user is reporting here.

1 Like

Thanks Firepup. That is exactly the issue. Even after removing Debug=True it still does not open a web page.

The strange thing is that everything works fine when Deployed, it’s just not feasible to redeploy every single time I want to update the codebase.

Hey Shane, this is the main problem I’m looking for help with. For whatever reason, running the project doesn’t show the output. I need to fully deploy via Replit deployments to see what the project looks like which isn’t viable for debugging and iterating on my code.

Oddly enough, when I remove debug=True from the app.run statement in a fork of your Repl, it loads just fine. Could you try forking your Repl and removing debug=True and seeing if that fixes your issue?

Huh, strange. Removing it from the main branch still isn’t quite doing the trick. I don’t even have the option to open a Webview tab from here.

You should have gotten this error in the lower right corner of your Repl when you ran that:

Port 5000 opened on host 127.0.0.1.
Use the host 0.0.0.0 to open the port to web traffic.

Using this ass your app.run statement instead should work:

  app.run(host='0.0.0.0')

I swore I had tried that, but maybe I tried in debug mode - either way this works! Thanks for your help.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.