Flask App deployed (using Docker); TemplateNotFound error
Hey guys,
I'm aware this is primarily a Flask issue however this works locally. The docker container is successfully being built and deployed via railway.app but whenever I visit the URL, it tells me it cannot find index.html in the templates folder. I've even gone as far as manually specifying the templates folder location for the Flask app via :
Any ideas?
75 Replies
Project ID:
564afc01-1a48-4844-a9fb-394914380c11
564afc01-1a48-4844-a9fb-394914380c11
Any questions, please ask.
https://dwellist.up.railway.app/
try using absolute paths
I did; even got that working locally but it just spits out the same error message on deployment
is the file in github?
if so, do the file and folder names have the same casing?
yes
I've even just thrown this in
and what's the outcome
Just a moment
Okay, so it says it exists
but it can't find the file locally
However, I think that's due to the absolute path for templates.
Scratch that, it still hates it
Working directory is '/app'
file path is '/app/app/templates/index.html'
your project is placed into an
/app
folder at the root of the container. but it shouldn't matter where your project is, your code should be able to work out the working directory and combine that with the relative paths to make absolute pathsI'm just going to change the root dir name from app to my project name dwellist
So path will be dwellist/app/templates/index.html
you can't change where nixpacks puts your code
What do you mean
This evaluation returns true; the file at index_path does exist
and yet
It's right friggin there
I've returned to this which works locally...
ah you are using a dockerfile, that would have been good information to have
Sorry, my bad
That's the only way I've been deploying; It's the first time I'm deploying with Docker like this
dockerfile*
Perhaps I've set it up incorrectly?
I assumed if it worked locally, it can work anywhere
does this work locally when you build and run the dockerfile?
Clearly a bad assumption on my part
Yep
and I don't mean just
python app.py
actually running the imageSo I do:
docker built -t dwellist -f docker/Dockerfile .
To run it
docker run -p 5000:5000 dwellist
index.html loads right up
But when deployed; it poops itselfare you sure railway is using your dockerfile to build?
It should be, I had to manually specify the location via the Variables in the settings
Dockerfile is in a docker folder at working directory
do the build logs confirm it's using a dockerfile and not nixpacks?
is railway using the same root directory that you use when you build the image?
That's what I'm not too sure about; I could add a print statement to find out? Unsure if that'd be an accurate representation but hey. Maybe there's another way to check?
Workdir is set to dwellist
by default railway uses the root of your project, what path do you use locally
this doesn't really have anything to do with the dockerfile
Surely that would be it right?
It's creating a new folder in the container called dwellist and copying all local files/folders to that new folder
not quite what I'm asking
I'm not sure how to answer the question 😬
Locally, I just execute from within dwellist
It's been a long day man
Cannot absord words
can you share your repo?
Sure
GitHub
GitHub - a-curious-coder/dwellist
Contribute to a-curious-coder/dwellist development by creating an account on GitHub.
I'm testing on branch 19
web scraper 😬
... yeah
That's disjoint for the moment though... isn't it?
do you have permission to scrape what you're scraping?
Rookie error on my part... I imagine there's law surrounding what can and cannot be used from SpareRoom?
I don't know, I'm asking you lol, does spare room allow web scraping?
I've made the assumption that since it's publicly accessible data it can be taken. They've got not rate limiters but they also don't have an API.
Honestly, I'm not sure really
I imagine if they explicitly state "You're not allowed" then it's not allowed? Otherwise it's a grey area?
yes this is a grey area, running a scraper on railway is in their tos
(: Definitely a mistake then.
If I get explicit permission, is that okay or still against tos?
Failing that, I could use fictional data?
I'd have to evidence that it's actually generated of course?
in the grand scheme of things, it's not that big of a deal
This project is moreso to help me learn the development process; idea to deployment, I don't mind too much if I don't use the data I scrape
Also the first time I've started using Issue / Project in Github so it's all a learning curve tbh.
I don't usually like helping with scraping projects here in these forms, so I'll help, as long as you'll agree to find an api to provide this data
scraping is unreliable anyway, it's for the better
Yeah, sure. When you say find an API; you generally mean an alternative data source (just because I'm not sure there's an API).
Nevermind
I found one 😄
https://developer.zoopla.co.uk/
if there's no api, you gotta ask yourself, is this a worthwhile project?
I'm not saying your project is bad, I don't even know what spare room is, that's just my opinion on web scraping
Aha, I'm not sure really; it's more to showcase knowledge for my portfolio
Ah, it's just a website people go to in order to rent properties
using an api is far more impressive than scraping
I'll throw it in then
I imagine this means I'd (ideally) have to remove the SpareRoom specific scraping logic from the project in order for this to be hosted on Railway.app?
ideally yeah, but it's not like they actively look for people doing web scraping, what you're doing is small peanuts
so either way, you've said you will use an api going forward, that's good with me
your folder structure is a bit unorthodox
if I wanted to run this project on my railway account would I need any kind of environment variables set?
Well there we are, I was trying to find the most orthodox folder structure for a flask app and this is one that I was given 😬
Nah, just the docker file specification
Tbh though, I wonder if it would be worth moving it to root
of the project
so you're saying I can fork this repo, slap in it a railway service and id get the same error you've shown?
Interestingly enough, I've put a little too much faith in AI to tell me the best directory structure for the project
Yep
ewww ai
Should work out of the box
In this instance, yeah 😂
I think it's good for basic and straightforward explanations but anything more and it craps itself
I've done a lot of help here, and most often than not ai just makes it worse
It's sent me down a rabbit hole or two
Made things more complicated than they had to be
should i fork branch 19
Yeah
That's the one I'm experimenting the deployment with
Even trying to get better at version control 😂 although the commit history definitely shows where I tried and failed
these look like good commit messages to me
where is index.html
https://github.com/brody192/dwellist/blob/19-docker-deployment-issues/.gitignore#L4
remember when i asked this
Oh my god
I am so sorry
🤣
I appreciate the help Brody, thank you. If it makes you feel like you've wasted time, I've learned the important lesson of not jumping the gun and specifically investigating to answer questions rather than assume.
So, for me, not a waste of time 🙂
ive not wasted time 🙂
oh also, please use gunicorn, you are running flask in development mode
I had a crack at that but I can't copy that on windows as there's a dependency gunicorn uses that's not available for windows
Although I suppose the point is to do the trial and error in the container
run the dev server locally, use gunicorn in your dockerfile
Ah okay 😄