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:報錯已經(jīng)很明顯了,whoosh_index函數(shù)要的是app ,但你轉(zhuǎn)入create_app函數(shù),檢查下吧!
相關(guān)文章:
1. css - 如何控制鼠標(biāo)事件?當(dāng)處于down時會觸發(fā)其他效果,而up的時候則會取消所有效果?2. 求助一個Android控件名稱3. vim - docker中新的ubuntu12.04鏡像,運(yùn)行vi提示,找不到命名.4. IOS app應(yīng)用軟件的id號怎么查詢?比如百度貼吧的app-id=4779278135. css - 關(guān)于offsetLeft和offsetTop6. javascript - video標(biāo)簽無法識別的視頻格式怎么辦?7. python - flask的errorhandler(BaseError)重寫方法后怎么獲得更多信息8. html5 - mui dialog 如何配置type屬性9. javascript - 微信內(nèi)置瀏覽器的ua是多少?10. html5 - 小程序的swiper那個點可以給他居右?
