OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Azure web app config build command for Flask

  • Thread starter Thread starter Biying Zhang
  • Start date Start date
B

Biying Zhang

Guest
enter image description here

My Flask App architecture.

I'm trying to deploy this to Azure web app. I run python main.py to serve the flask app and I have init.py inside website which is the actual Flask project folder. How can I configure Azure so that it runs python main.py on build instead of trying to locate a Flask module?

my main.py looks like:

Code:
from website import create_app
import os
app = create_app()

if __name__ == '__main__':
    os.system('sass website/static/sass/main.scss website/static/style.css')
    app.run(debug=True)

and my init.py inside website:

Code:
from flask import Flask, redirect, flash
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager, current_user
from functools import wraps

db = SQLAlchemy()
app = Flask(__name__)

# some custom decorators here


def create_app():
    app.config['SECRET_KEY'] = 'RANDOM string'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:password@localhost/hlrc'

    app.config['SESSION_COOKIE_SAMESITE'] = 'Strict'
    app.config['SESSION_COOKIE_SECURE'] = True

    db.init_app(app)

    with app.app_context():
        db.Model.metadata.reflect(db.engine)

    from website.bp.auth import auth
    from website.bp.home import home
    from website.bp.patient import patient
    from website.bp.study import study
    from website.bp.visit import visit
    from website.bp.report import report
    from website.bp.pft import pft
    from website.bp.mmrc import mmrc
    from website.bp.pq import pq
    from website.bp.sgrq import sgrq

    app.register_blueprint(home, url_prefix='/')
    app.register_blueprint(auth, url_prefix='/')
    app.register_blueprint(patient, url_prefix='/patient')
    app.register_blueprint(study, url_prefix='/study')
    app.register_blueprint(visit, url_prefix='/visit')
    app.register_blueprint(report, url_prefix='/report')
    app.register_blueprint(pft, url_prefix='/pft')
    app.register_blueprint(mmrc, url_prefix='/mmrc')
    app.register_blueprint(pq, url_prefix='/pq')
    app.register_blueprint(sgrq, url_prefix='/sgrq')


    login_manager = LoginManager()
    login_manager.login_view = 'auth.login'
    login_manager.init_app(app)

    from .models import User

    @login_manager.user_loader
    def load_user(id):
        return User.query.get(int(id))

    return app

I would really hope I don't have to re-architect my Flask app because "if it works don't touch it". I am aware of the option to customise startup command in Azure but I don't know what/how to configure in my case.

Any help would be appreciated!
<p><a href="https://i.sstatic.net/zOYVPfr5.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/zOYVPfr5.png" alt="enter image description here" /></a></p>
<p>My Flask App architecture.</p>
<p>I'm trying to deploy this to Azure web app. I run <code>python main.py</code> to serve the flask app and I have <strong>init</strong>.py inside <code>website</code> which is the actual Flask project folder.
How can I configure Azure so that it runs <code>python main.py</code> on build instead of trying to locate a Flask module?</p>
<p>my main.py looks like:</p>
<pre><code>from website import create_app
import os
app = create_app()

if __name__ == '__main__':
os.system('sass website/static/sass/main.scss website/static/style.css')
app.run(debug=True)
</code></pre>
<p>and my <strong>init</strong>.py inside website:</p>
<pre><code>from flask import Flask, redirect, flash
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager, current_user
from functools import wraps

db = SQLAlchemy()
app = Flask(__name__)

# some custom decorators here


def create_app():
app.config['SECRET_KEY'] = 'RANDOM string'
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:password@localhost/hlrc'

app.config['SESSION_COOKIE_SAMESITE'] = 'Strict'
app.config['SESSION_COOKIE_SECURE'] = True

db.init_app(app)

with app.app_context():
db.Model.metadata.reflect(db.engine)

from website.bp.auth import auth
from website.bp.home import home
from website.bp.patient import patient
from website.bp.study import study
from website.bp.visit import visit
from website.bp.report import report
from website.bp.pft import pft
from website.bp.mmrc import mmrc
from website.bp.pq import pq
from website.bp.sgrq import sgrq

app.register_blueprint(home, url_prefix='/')
app.register_blueprint(auth, url_prefix='/')
app.register_blueprint(patient, url_prefix='/patient')
app.register_blueprint(study, url_prefix='/study')
app.register_blueprint(visit, url_prefix='/visit')
app.register_blueprint(report, url_prefix='/report')
app.register_blueprint(pft, url_prefix='/pft')
app.register_blueprint(mmrc, url_prefix='/mmrc')
app.register_blueprint(pq, url_prefix='/pq')
app.register_blueprint(sgrq, url_prefix='/sgrq')


login_manager = LoginManager()
login_manager.login_view = 'auth.login'
login_manager.init_app(app)

from .models import User

@login_manager.user_loader
def load_user(id):
return User.query.get(int(id))

return app



</code></pre>
<p>I would really hope I don't have to re-architect my Flask app because "if it works don't touch it".
I am aware of the option to customise startup command in Azure but I don't know what/how to configure in my case.</p>
<p>Any help would be appreciated!</p>
Continue reading...
 

Latest posts

M
Replies
0
Views
1
MOHAMED AMIIN ABDI AADAN
M
Top