python - 使用WhooshAlchemy报错’function’ object has no attribute ’config’
问题描述
我想用WhooshAlchemy做全文搜索,但是用的时候报错:
我的config.py:import osfrom app import basedirCSRF_ENABLED = TrueSECRET_KEY = ’hard to guess string’SQLALCHEMY_TRACK_MODIFICATIONS = Falsebasedir = os.path.abspath(os.path.dirname(__file__))WHOOSH_BASE = os.path.join(basedir, ’search.db’)__init__.py:
def create_app():
app = Flask(__name__)app.config.from_pyfile(’config’)app.config[’SQLALCHEMY_DATABASE_URI’] = ’sqlite:///’ + path.join(basedir, ’data.sqlite’)# ’mysql://root:123456@localhost/shop’app.config[’SQLALCHEMY_COMMIT_ON_TEARDOWN’] = Trueapp.config.from_object(’config’)db.init_app(app)bootstrap.init_app(app)login_manager.init_app(app)from auth import auth as auth_blueprintfrom main import main as main_blueprint
models.py:class Post(db.Model):
__tablename__ = ’posts’__searchable__ = [’title’]id = db.Column(db.Integer, primary_key=True)title = db.Column(db.String)body = db.Column(db.String)created = db.Column(db.DateTime, index=True, default=datetime.utcnow)clicks = db.Column(db.Integer)comments = db.relationship(’Comment’, backref=’post’, lazy=’dynamic’)author_id = db.Column(db.Integer, db.ForeignKey(’users.id’))
if enable_search:
whooshalchemy.whoosh_index(app, Post)
问题解答
回答1:报错已经很明显了,whoosh_index函数要的是app ,但你转入create_app函数,检查下吧!
相关文章:
1. html5 - 百度Ueditor代码高亮和代码段滚动条冲突是怎么回事?2. css - 关于input标签disabled问题3. javascript - 关于一段 for 循环代码执行顺序的问题4. javascript - 静态页面引公共头尾文件,js怎么写吖?5. debian - docker依赖的aufs-tools源码哪里可以找到啊?6. docker api 开发的端口怎么获取?7. javascript - vue 数据更新了。但是dom没有更新,,,,,如图8. java - 为什么要将Runnable接口的子类对象传递给Thread的构造函数?9. 如何调整IDEA中直接运行java程序的日志输出级别?10. java基础,求解答。