python - Separate SQLAlchemy models by file in Flask -
python - Separate SQLAlchemy models by file in Flask -
this question has reply here:
flask-sqlalchemy import/context issue 2 answersmany examples flask apps have seen have models stored straight in main app file (http://pythonhosted.org/flask-sqlalchemy/quickstart.html, http://maximebf.com/blog/2012/10/building-websites-in-python-with-flask/). other ones (http://flask.pocoo.org/docs/patterns/sqlalchemy/) have "models.py" file in models placed.
how can have flask app import models separate files, e.x. "user.py"? when seek creating user.py file these contents:
from app import db class user(db.model): [...]
i next error:
file "/users/stackoverflow/myapp/models/user.py", line 1, in <module> app import db importerror: no module named app
when insert from models import user
in module file.
this reply extremely helpful: http://stackoverflow.com/a/9695045/353878.
i needed not initialize db right away.
python sqlalchemy flask flask-sqlalchemy
Comments
Post a Comment