我正在构建一个Flask需要后台进程导致上传到SQLAlchemy数据库的应用程序。
相关片段:
from flask_sqlalchemy import SQLAlchemy
import concurrent.futures
import queue
from models import Upload_Tracks
app = Flask(__name__)
db.init_app(app)
app.config.update(
SQLALCHEMY_DATABASE_URI= "sqlite:///%s" % os.path.join(app.root_path, 'path/to/player.sqlite3'))
q = queue.Queue()
在database.py:
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
在models.py:
def Upload_Tracks(item):
uri = None
title = unidecode(item['title'])
artist = unidecode(item['artist'])
preview = item['preview']
energy = item['energy']
popularity = item['popularity']
tempo = item['tempo']
brightness = item['brightness']
key = item['key']
image = item['artist_image']
duration = item['duration']
loudness = item['loudness']
valence = item['valence']
genre = item['genre']
track = Track(title=title,
artist=artist,
uri=uri,
track_id=None)
db.session.add(track)
track.preview = preview
track.energy = energy
track.popularity = popularity
track.tempo = tempo
track.genre = genre
track.brightness = brightness
track.key = key
track.image = image
track.duration = duration
track.loudness = loudness
track.valence = valence
db.session.commit()
数据库工作正常,没有线程。但是,当我运行它时,会捕获以下异常:
co/mp3-preview/c0d57fed887ea2dbd7f69c7209adab71671b9e6e?cid=d3b2f7a12362468daa393cf457185973 '} 生成了一个异常:未找到应用程序。在视图函数内工作或推送应用程序上下文。请参阅http://flask-sqlalchemy.pocoo.org/contexts/。
但据我所知,这个过程是在@app.route
. 这怎么断章取义了?我该如何解决?
相关分类