python - l'objet d'erreur 'fonction' n'a pas d'attribut 'config' lors de l'utilisation de WhooshAlchemy
習慣沉默
習慣沉默 2017-05-27 17:39:40
0
1
1228

Je souhaite utiliser WhooshAlchemy pour la recherche en texte intégral, mais lorsque je l'utilise, j'obtiens une erreur :

Mon config.py :
import os
from app import basedir
CSRF_ENABLED = True
SECRET_KEY = 'chaîne difficile à deviner'
SQLALCHEMY_TRACK_MODIFICATIONS = False
basedir = 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'] = True
app.config.from_object('config')
db.init_app(app)
bootstrap.init_app(app)
login_manager.init_app(app)
from auth import auth as auth_blueprint
from 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'))

si activate_search :

whooshalchemy.whoosh_index(app, Post)
習慣沉默
習慣沉默

répondre à tous(1)
曾经蜡笔没有小新

L'erreur est déjà évidente. La fonction whoosh_index nécessite une application, mais vous passez à la fonction create_app et vérifiez-la !

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!