a year ago
I need to preface this by saying that I am not an IT guy, really not at all...I know some basic python, as soon as we get into pots and networking and pc stuff I'm lost.
I built a flask appliation, everything is working fine when I host it on my desktop. I've deployed it to Railway, it's deploying and running, at least according to the logs, its running my code prior to any traffic....it just isn't getting any traffic. I.e. when I click the link, it doesn't return anything, eventually it comes back with 'site can't be reached'.
I've watched a bunch of tutorials and feel like ive done every thing right. I've got my Procfile set up, with "web: gunicorn app:app" (app.py is my main file). All the packages seem to have installed from requirements.txt, otherwise I can't see how the app will have initialised and made the initial computations it makes before starting the flask app. I'm starting the app with
app.run(debug=False, host='0.0.0.0', port=5000)
Other than that, I really don't know what to share with you because I have no idea where the issue might be!
Would love some help :). If I can get this sorted then I'll upgrade to pro for sure, because I like the interface, it's easy to understand, but not before that.
8 Replies
a year ago
You are likely missing this line of code from your app.py file -
https://github.com/railwayapp-templates/flask/blob/main/main.py#L12
a year ago
Brilliant!!
a year ago
I had another question for you, but I realised Im not ready to ask it....not sure how to delete this
Status changed to Solved brody • 11 months ago
Status changed to Open burrunjor • 11 months ago
a year ago
So this has thrown me into another tangle. Given that the app declaration and the webhook functions apparently need to be at the top, not below the name==main, I can't figure out how to pass other objects that I want to create on starting the app, before any requests come in, to be used by the webhook functions. Even though I can get the app to work in a variety of ways on my machine, this stipulation for hosting it with gunicon, seems to be blocking me from going further....I can't see how to do anything other than process basic requests based on whatever variables I define at the time of the post....which isn't enough. I find it odd that gunicorn wants the app declaration up there, I would have thought that it would have run the file more intuitively by going from below the name== main, apparently it doesn't?
I can see on stack overflow ways to use factories to return the app, but this would remove it from the top.
Any thoughs? I know this is getting complicated, but actually, to run it on the PC it wasn't really.
It's like the webhooks are moved off into a different planet, and the world of python, with all the things it can do, is unable to do anything. Or at least, it is all of a sudden, very unclear how to make use of it.
a year ago
Its fixed!!!
The light went on when I realised what gunicorn was doing, its taking over the run command.
I changed it at the top so that gunicorn is firing function instead, at the very top (above the call). Which returns a tuple of everything i need.
I build the other objects in the create_app function, return those in positions 1 and 2, and also return the app at position 0 of the tuple, then redefined the app variable so its just the app.
After that the variables are n the name space and can be picked up by all of the following functions.
Only the app.run command needs to be below the name==main.
What im still fuzzy about is when or what calls the if name == main part, but no matter, I dont care anymore :)
app = create_app()
otherObjects = app[1]
OtherObject2 = app[2]
app = app[0]
a year ago
Seems a bit awkward, but whatever, it works
Status changed to Solved brody • 11 months ago