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. python - django 里自定義的 login 方法,如何使用 login_required()2. python如何不改動文件的情況下修改文件的 修改日期3. angular.js - Angular路由和express路由的組合使用問題4. angular.js - angularjs 用ng-reapt渲染的dom 怎么獲取上面的屬性5. mysql優化 - mysql count(id)查詢速度如何優化?6. 主從備份 - 跪求mysql 高可用主從方案7. css3 - [CSS] 動畫效果 3D翻轉bug8. angular.js - 不適用其他構建工具,怎么搭建angular1項目9. mysql主從 - 請教下mysql 主動-被動模式的雙主配置 和 主從配置在應用上有什么區別?10. node.js - node_moduls太多了
![css3 - [CSS] 動畫效果 3D翻轉bug](http://www.cgvv.com.cn/attached/image/news/202304/110831f073.png)