python - 使用WhooshAlchemy报错'function' object has no attribute 'config'

查看:200
本文介绍了python - 使用WhooshAlchemy报错'function' object has no attribute 'config'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

我想用WhooshAlchemy做全文搜索,但是用的时候报错:

我的config.py:
import os
from app import basedir
CSRF_ENABLED = True
SECRET_KEY = 'hard to guess string'
SQLALCHEMY_TRACK_MODIFICATIONS = False
basedir = 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'] = True
app.config.from_object('config')
db.init_app(app)
bootstrap.init_app(app)
login_manager.init_app(app)
from auth import auth as auth_blueprint
from 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)

解决方案

报错已经很明显了,whoosh_index函数要的是app ,但你转入create_app函数,检查下吧!

这篇关于python - 使用WhooshAlchemy报错'function' object has no attribute 'config'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆