R
Railway•15mo ago
pisquared2

Flask app not working

hey there am very new to railway, i would love to get some help, I am not familiar with hosting a website either. i would appreciate it if someone could walk me through setting it up, I've seen some youtube tutorials about hosting a flask app on railway but none of them worked for some reason.
31 Replies
Percy
Percy•15mo ago
Project ID: b18dbcc6-1581-49d3-9f4b-7a0659942430
pisquared2
pisquared2•15mo ago
proejct id: b18dbcc6-1581-49d3-9f4b-7a0659942430
jonbeau
jonbeau•15mo ago
Hey, railway provides an env variable port. Could you ensure your app is listening on this, rather than 5000 or however it is currently configured?
pisquared2
pisquared2•15mo ago
how can I do that sorry but I've never hosted an app before
jonbeau
jonbeau•15mo ago
Can you share your repo?
pisquared2
pisquared2•15mo ago
GitHub
GitHub - AhmedMurad22/PastPaperHelper
Contribute to AhmedMurad22/PastPaperHelper development by creating an account on GitHub.
jonbeau
jonbeau•15mo ago
Change like this
- app.run(debug=True)

+ import os
+ PORT = os.getenv('PORT')
+ app.run(host='0.0.0.0', port = PORT, debug=True)
- app.run(debug=True)

+ import os
+ PORT = os.getenv('PORT')
+ app.run(host='0.0.0.0', port = PORT, debug=True)
pisquared2
pisquared2•15mo ago
oh it worked but now i get this error after pressing one of the buttons
pisquared2
pisquared2•15mo ago
pisquared2
pisquared2•15mo ago
i think because tabula-py relies on java
jonbeau
jonbeau•15mo ago
I think here you need to add java as one of the build providers. If that doesn't work, someone smarter than me might have to help. 🙂
pisquared2
pisquared2•15mo ago
ill try that :) wait.. I dont have that option in settings
pisquared2
pisquared2•15mo ago
jonbeau
jonbeau•15mo ago
Oh, you need to join priority boarding for that apparently. There's also a way to do it with config file I'm sure but I'm on my phone now and not the most familiar with it. You can join that with /beta
pisquared2
pisquared2•15mo ago
oh alright, thank you man, appreciate the help!! <3 hey there man 🤣 new day new error
pisquared2
pisquared2•15mo ago
jonbeau
jonbeau•15mo ago
Did adding java in the profiders work? I think you can just add a nixpacks.toml file in your root with
providers = ['...', 'java']
providers = ['...', 'java']
or something like this This looks like an error with your code. There is no year. It should be like this:
pisquared2
pisquared2•15mo ago
i added java in the providers
jonbeau
jonbeau•15mo ago
year = request.form.get('year') if year: your code
pisquared2
pisquared2•15mo ago
now this is the error that it gives how does it work perfectly fine on a local host then??
pisquared2
pisquared2•15mo ago
pisquared2
pisquared2•15mo ago
where do I add this text?
jonbeau
jonbeau•15mo ago
Are you sure you selected a year when you receive this error? if you use year = request.form['year'] and there is no year selected you will get an error. if you do something like:
year = request.form.get('year')
if year:
print(year)
else:
year = 2022
year = request.form.get('year')
if year:
print(year)
else:
year = 2022
then it will set the year to 2022 if no year is selected, hope this helps
pisquared2
pisquared2•15mo ago
it works perfectly fine in a local host am pretty sure the problem is not with "year"
jonbeau
jonbeau•15mo ago
year = request.form['year'] will be a null value and you cant use it if year is not selected on the form
jonbeau
jonbeau•15mo ago
but im just using year as an example, it's the same for all the fields I'm not sure why it works locally unless you had selected all the fields
pisquared2
pisquared2•15mo ago
the website requests a pdf from a different website, does that have anything to do with it? thats really weird
jonbeau
jonbeau•15mo ago
ill look at your code again shortly but you should put some error handling to flash a message to your user if they forgot to fill out the whole form https://flask.palletsprojects.com/en/2.3.x/patterns/flashing/
pisquared2
pisquared2•15mo ago
alr man thanks!!
jonbeau
jonbeau•15mo ago
it shouldn't be an issue in a railway.toml file in your root directory
Want results from more Discord servers?
Add your server