I recently started getting into Flask web dev and I've probably gone through 5 different courses/tutorials now, and they all seem to have different ways/conventions of doing things. I was hoping I could receive some clarity here!
if __name__ == '__main__':
app.run(debug=True)
# Initialize as blueprint
users = Blueprint('users', __name__, url_prefix="/users")
# Load .env.local file and specify relative path
load_dotenv(dotenv_path="./.env.local")
# Database config
users.config["SECRET_KEY"] = "mysecretkey"
users.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get("SQLITE_URI", "")
users.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
The tutorial uses "app.config" obviously, but my "app" exists in my __init__.py and not in this users.py , so is there a way of using config in this users file? Should it be done in __init__.py instead?
Sorry for the lengthy post of questions, thank you in advance for anyone who can help me!
Question 4
Simple answer is NO.
The statement if __name__ == '__main__': is used only if you expect the python file to be executed using its file name.
If you have a python file that only has helper functions and does not do anything else, you may not include this statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With