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. angular.js - 如何通俗易懂的解釋“依賴注入”?2. django - 后臺(tái)返回的json數(shù)據(jù)經(jīng)過Base64加密,獲取時(shí)用python如何解密~!3. 我的html頁面一提交,網(wǎng)頁便顯示出了我的php代碼,求問是什么原因?4. 我在centos容器里安裝docker,也就是在容器里安裝容器,報(bào)錯(cuò)了?5. css3 - 請(qǐng)問一下在移動(dòng)端CSS布局布局中通常需要用到哪些元素,屬性?6. 老哥們求助啊7. javascript - vue-router怎么不能實(shí)現(xiàn)跳轉(zhuǎn)呢8. tp6表單令牌9. html5 - angularjs中外部模版加載無法使用10. node.js - node 客戶端socket一直報(bào)錯(cuò)Error: read ECONNRESET,用php的socket沒問題哈。。
