Skip to content
← Back to Community
Python Flask Code is Not working
Profile icon
Pizzaz4me

Why is my python flask code not working? It keeps leading me to this site saying my website refused to connect

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
Profile icon
Pizzaz4me
Comments
hotnewtop
Profile icon
Coder100

Repl.it only hosts when your IP is 0.0.0.0.

So replace your code in line 9-10:

if __name__ == "__main__": app.run(host='0.0.0.0', port='8080', debug=True)

That's it! Easy, right?

Profile icon
Pizzaz4me

Thanks. I would give you 10 cycles if I could @Coder100

Profile icon
Coder100

lol np :) @PlaySoccer

Profile icon
gibbsfreenergy

Hey there! So this is a pretty common problem, you need a port if you want the flask to open, so copy this code on line 8:

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

Seems many people experience this annoying issue, follow my shortcut here:
1. Open a new repl, then press the examples button:

image

2. Press the first example, it is called Flask (server):

image

So there you go, a much simpler shortcut!

Hope this helped and have fun coding :)

Profile icon
gibbsfreenergy

@PlaySoccer Not even a thank you?!? :(

Profile icon
Pizzaz4me

Oh sorry @JosehSanthosh. I didn't see your comment.

Profile icon
Pizzaz4me

I always need to refresh the page when I click my notifications. I just forgot to do it when I saw that @Coder100 replied to my post. I did not want to be rude @JosephSantosh

Profile icon
gibbsfreenergy

Oh, I'm so sorry for making it seem that way! Well thx for telling me! :) @PlaySoccer

Profile icon
Pizzaz4me
Profile icon
crw2e

I tried this, and I'm still getting the same issue. Is this something that is beyond my control? (I'm on the school wifi, for context).