国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

python - 使用WhooshAlchemy報錯’function’ object has no attribute ’config’

瀏覽:144日期:2022-06-30 08:59:39

問題描述

我想用WhooshAlchemy做全文搜索,但是用的時候報錯:

python - 使用WhooshAlchemy報錯’function’ object has no attribute ’config’

我的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函數,檢查下吧!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 陇西县| 景宁| 蒲江县| 宁安市| 油尖旺区| 东乡县| 永昌县| 焉耆| 吴桥县| 凤凰县| 星子县| 东辽县| 丰县| 北票市| 庄河市| 阿合奇县| 高陵县| 蕉岭县| 衡东县| 旬阳县| 莱西市| 谢通门县| 昔阳县| 凤凰县| 江北区| 金秀| 都昌县| 太谷县| 昆山市| 长白| 宣化县| 马公市| 汾阳市| 太谷县| 习水县| 信宜市| 巴马| 大余县| 中宁县| 泰和县| 廉江市|