python - 使用WhooshAlchemy報(bào)錯(cuò)’function’ object has no attribute ’config’
問題描述
我想用WhooshAlchemy做全文搜索,但是用的時(shí)候報(bào)錯(cuò):
我的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:報(bào)錯(cuò)已經(jīng)很明顯了,whoosh_index函數(shù)要的是app ,但你轉(zhuǎn)入create_app函數(shù),檢查下吧!
相關(guān)文章:
1. javascript - 這兩種函數(shù)寫法各有什么好處?2. 微信支付 - python做微信企業(yè)付款出現(xiàn)CA證書錯(cuò)誤3. 前端 - css3傾斜帶來問題部分?4. node.js - vue 子組件的菜單 如何與 父組件 通信?5. javascript - node環(huán)境使用vue-cli 配置代理6. 了解Java中的有限泛型。有什么意義?7. angular.js - 在ionic下,利用javascript導(dǎo)入百度地圖,pc端可以顯示,移動(dòng)端無法顯示8. html5 - HTML代碼中的文字亂碼是怎么回事?9. html5 - 如何禁止百度轉(zhuǎn)碼?10. angular.js - vue or angular.2 or react
