Hi pafk,
thank you for taking a look. I admit it is little bit puzzling because the way I had it set up worked fine until now,
then I changed code to pull config depending on environmental variable defined in .bashrc
file.
import os
from logging import FileHandler
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from flask_migrate import Migrate
from flask_bcrypt import Bcrypt
from flask_mail import Mail
if os.environ.get('FLASK_ENV') == 'production':
from project.config import ProductionConfig
current_config = ProductionConfig
elif os.environ.get('FLASK_ENV') == 'staging':
from project.config import StagingConfig
current_config = StagingConfig
login_mgr = LoginManager()
migrate = Migrate()
bcrypt = Bcrypt()
db = SQLAlchemy()
migrate = Migrate()
mail = Mail()
def create_app(script_info=None):
if os.environ.get('FLASK_ENV') == 'production':
if not os.path.exists('/home/markalexa/blog/project/api/images'):
os.mkdir('project/api/images')
os.mkdir('project/api/images/post')
os.mkdir('project/api/images/card')
app = Flask(__name__, template_folder='/home/markalexa/blog/client/build', static_folder='/home/markalexa/blog/client/build/static')
file_handler = FileHandler('/home/markalexa/blog/project/errorlog.txt')
elif os.environ.get('FLASK_ENV') == 'staging':
if not os.path.exists('/home/pyseostaging/staging/project/api/images'):
os.mkdir('project/api/images')
os.mkdir('project/api/images/post')
os.mkdir('project/api/images/card')
app = Flask(__name__, template_folder='/home/pyseostaging/staging/client/build', static_folder='/home/pyseostaging/staging/client/build/static')
file_handler = FileHandler('/home/pyseostaging/staging/project/errorlog.txt')
app.logger.addHandler(file_handler)
app.config.from_object(current_config)
db.init_app(app)
bcrypt.init_app(app)
migrate.init_app(app, db)
if os.environ.get('FLASK_ENV') == 'development':
toolbar.init_app(app)
login_mgr.init_app(app)
login_mgr.session_protection = "strong"
from project.api.models import Commander, Users, Posts, Comments
from project.api.blog import blog_blueprint
from project.api.auth import auth_blueprint
app.register_blueprint(blog_blueprint)
app.register_blueprint(auth_blueprint)
@app.errorhandler(404)
def error_handler(e):
return render_template('index.html')
return app
app = create_app()
the above __init__
file worked just fine until I added ifs with os.environ.get()
conditional statements.
running echo $FLASK_ENV
gives me staging
as expected but the script isn't taking it.
Sorry I know this is rather Python logic issue than issue with PA per se.