python - 使用WhooshAlchemy報(bào)錯(cuò)’function’ object has no attribute ’config’
問(wèn)題描述
我想用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)
問(wèn)題解答
回答1:報(bào)錯(cuò)已經(jīng)很明顯了,whoosh_index函數(shù)要的是app ,但你轉(zhuǎn)入create_app函數(shù),檢查下吧!
相關(guān)文章:
1. boot2docker無(wú)法啟動(dòng)2. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””3. docker-compose中volumes的問(wèn)題4. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.5. nignx - docker內(nèi)nginx 80端口被占用6. java - SSH框架中寫(xiě)分頁(yè)時(shí)service層中不能注入分頁(yè)類7. javascript - mock.js可以存儲(chǔ)數(shù)據(jù)嗎8. docker api 開(kāi)發(fā)的端口怎么獲取?9. docker images顯示的鏡像過(guò)多,狗眼被亮瞎了,怎么辦?10. golang - 用IDE看docker源碼時(shí)的小問(wèn)題

網(wǎng)公網(wǎng)安備