python世界的新手,建议尝试cookiecutter-flask,但遇到了问题:
我手动生成了一个迁移"而不是基于模型。在我意识到模型可用于生成迁移之类的模型之后,#34; stock"使用cookiecutter - 我删除了我的手动迁移,但似乎无法让模型生成迁移文件。
在app.py中
from project import commands, public, user, category
def register_blueprints(app):
"""Register Flask blueprints."""
app.register_blueprint(public.views.blueprint)
app.register_blueprint(user.views.blueprint)
app.register_blueprint(category.views.blueprint) <- my model
return None
在视图中
blueprint = Blueprint('category', __name__, url_prefix='/categories', static_folder='../static')
我的路线似乎被检测到了
#flask urls
/categories/ category.categories
/categories/static/<path:filename> category.static
但是当我跑步时
#flask db migrate
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.autogenerate.compare] Detected added table 'users'
INFO [alembic.autogenerate.compare] Detected added table 'roles'
它似乎无法检测到类别模型,我迷失了我在这里缺少的东西?
答案 0 :(得分:0)
哦,问题最终是这样:
我的模型基于cookiecutter附带的Users模型。在视图中,我们从不导入显然应该导入的用户模型,而是机制似乎依赖于public / views.py导入它
from project.user.models import User
因为在register_blueprints()之前公共加载,我们在处理用户视图时已经可以访问User模型。
所以tl; dr需要在whatevermodel / views.py中导入为
from project.category.models import Category
对我而言,听起来有点过于神奇,并依赖公众在用户面前加载......