sekgobela-kevin / natrec

Natrec is an AI tool offering text generation, language translation, creative content writing, and accurate question answering
0 stars 0 forks source link

Take advantage of Flask Blueprints #1

Open sekgobela-kevin opened 10 months ago

sekgobela-kevin commented 10 months ago

Flask routes in the application are associated with the app directly which can make it hard to assocate application with other apps. The routes being on the app will force natrec to run as individual website on its own domain. Blueprints make are life saver as they allow to group flask routes which can then be registered to app.

Here is example of using blueprints

# app.py
from flask import Flask
from blueprints import main_blueprint, admin_blueprint

app = Flask(__name__)

# Register blueprints
app.register_blueprint(main_blueprint)
app.register_blueprint(admin_blueprint, url_prefix='/admin')

if __name__ == '__main__':
    app.run()

# blueprints.py
from flask import Blueprint, render_template

main_blueprint = Blueprint('main', __name__)

@main_blueprint.route('/')
def index():
    return render_template('index.html')

admin_blueprint = Blueprint('admin', __name__)

@admin_blueprint.route('/')
def admin_index():
    return render_template('admin/index.html')
sekgobela-kevin commented 10 months ago

The whole site can be designed to be as part of a blueprint which can be registered with an app. Instead of our app being accessible though domain it can be accesed as something like example.com/natrec. Using blueprints is optional but can make it easier to showcase presentatic on another web app.