Feb-13-2023, 05:45 PM
Hi Dean, thanks for your reply!
Here's what routes.py looks like:
ie, the interpreter sees
Here's what routes.py looks like:
import os, subprocess from flask import render_template, request, redirect, url_for, jsonify from myproject import app, db from myproject.models import Session, Utterance from myproject.mymodule import myfunction #this module contains a global that can only be instantiated onceNote that my previous post abbreviated __init__.py for clarity. The entire script also instantiates a db as so:
from flask import Flask from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) # configure the SQLite database, relative to the app instance folder app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) from myproject import routesI was thinking that since __init__.py defines
app
before it import routes
, it would at that point be safe to import app
from inside routes.py (without it becoming circular). ie, the interpreter sees
app
in __initi__.py, then import routes
. Inside routes.py, when it sees import app
, it says, 'ok, I already know about app' and all is well...No?