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. dockerfile - 为什么docker容器启动不了?2. docker - 各位电脑上有多少个容器啊?容器一多,自己都搞混了,咋办呢?3. docker gitlab 如何git clone?4. nignx - docker内nginx 80端口被占用5. javascript - 修改表单多选项时和后台同事配合的问题。6. redis - 究竟是选择微信小程序自带的统计工具还是自己开发一个数据统计的代码?7. docker安装后出现Cannot connect to the Docker daemon.8. 我在centos容器里安装docker,也就是在容器里安装容器,报错了?9. golang - 用IDE看docker源码时的小问题10. javascript - 怎么实现点击表格中的某一行然后就在表单处出现表格中的对应的属性值啊

网公网安备