How to render a flask app with __init__.py?

Hello, render world!

I’m having some trouble. I don’t know how to proper deploy a Flask app I’ve made (and runs well locally).

It’s a somewhat complex app, so I didn’t used app.py but a __init__.py module with Blueprints. The problem is that I always get ModuleNotFoundError: No module named 'app' at the deploy. I am a beginner, but the other two apps I’ve made run beautifully on Render (but they are smaller, so everything is inside app.py).

I’ve tried to create a environment variable called “FLASK_APP=init.py” but it didn’t worked. What should I do?

Hello? Somebody can help me?

Hey, not sure what’s wrong, but it could be a file pathing issue. You might be able to solve it by putting init.py in an “app” folder. It’s been a while since I’ve used flask, so without seeing your codebase, I’m unable to identify the issue. Maybe someone from the Render team who has access can help?

The problem really was the directory path!

The solution was to reorganize the files and change the build command. The build command should be gunicorn "directoryname:create_app()" (in my case, directoryname = watchlist) and the files was reorganized as follows:

repo
|
requirements.txt
.flaskenv
watchlist
--__init__.py
--routes.py
--other files

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