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. javascript - Vue.js的ElementUI库中,如何主动触发checkbox组件的change事件?2. javascript - webpack 打包 reactjs项目 css 分离3. javascript - 关于js高级程序中的问题4. javascript - 关于微信扫一扫的技术问题5. javascript - 如何清除向可编辑的(contenteditable)元素里粘贴的文本的标签和样式?6. javascript - 请教移动端从详情页返回到列表页原来位置的问题?7. javascript - vuex中子组件无法调用公共状态8. javascript - (_a = [""], _a.raw = [""],....); js一个小括号的是什么意思?9. javascript - js正则替换日期格式问题10. javascript - ios上fixed定位问题,定位在底部的按钮不显示了,但是又可以点击到,换了一个类名就可以显示了,但是设置的字体大小却失效了
