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 - node.js promise沒用2. android 如何實(shí)現(xiàn)如圖中的鍵盤上的公式及edittext的內(nèi)容展示呢3. c++ - 如何正確的使用QWebEngineView?4. yii2中restful配置好后在nginx下報(bào)404錯(cuò)誤5. javascript - js 寫一個(gè)正則 提取文本中的數(shù)據(jù)6. 算法 - python 給定一個(gè)正整數(shù)a和一個(gè)包含任意個(gè)正整數(shù)的 列表 b,求所有<=a 的加法組合7. golang - 用IDE看docker源碼時(shí)的小問題8. ruby - gitlab托管,git clone 失敗?9. java - 我在用Struts2上傳文件時(shí),報(bào)以下錯(cuò)誤怎么回事?10. 網(wǎng)站被黑,請教下大神,怎么對datebase.php內(nèi)容加密。
