1

运行烧瓶应用程序时出现以下错误,并且在我将应用程序从窗口迁移到 Linux 后,此问题开始出现,在 Windows 10 上烧瓶工作正常。我已经安装了所有依赖项,它在我看来是一些配置错误,所以请告知。

下面是错误信息。

RuntimeError: no destination for set images Traceback(最近一次调用最后一次)

File "/root/app/shop-blog-app/__init__.py", line 61, in <module>

configure_uploads(app, images)

File "/usr/local/lib/python3.7/dist-packages/flask_uploads.py", line 217, in configure_uploads

config = config_for_set(uset, app, defaults)

File "/usr/local/lib/python3.7/dist-packages/flask_uploads.py", line 185, in config_for_set

raise RuntimeError("no destination for set %s" % uset.name)

RuntimeError: no destination for set images

==================

/usr/local/lib/python3.7/dist-packages/flask_sqlalchemy/__init__.py:835: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
  'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
127.0.0.1 - - [14/Jan/2021 16:18:16] "GET / HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/root/app/shop-blog-app/__init__.py", line 61, in <module>
    configure_uploads(app, images)
  File "/usr/local/lib/python3.7/dist-packages/flask_uploads.py", line 217, in configure_uploads
    config = config_for_set(uset, app, defaults)
  File "/usr/local/lib/python3.7/dist-packages/flask_uploads.py", line 185, in config_for_set
    raise RuntimeError("no destination for set %s" % uset.name)


配置文件

import os
basedir = os.path.abspath(os.path.dirname(__file__))
#TOP_LEVEL_DIR = os.path.abspath(os.curdir)
TOP_LEVEL_DIR = os.path.join()

print(TOP_LEVEL_DIR)

class Config(object):
    SECRET_KEY =  'test'
    #SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'app.db')
    SQLALCHEMY_DATABASE_URI = 'mysql://root:redhat@localhost:3306/flaskdb'
    #SQLALCHEMY_ECHO = True
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    UPLOADED_PHOTO_DEST = os.path.dirname(os.path.abspath(__file__))
    UPLOADED_PHOTO_ALLOW = 'IMAGES'
    UPLOADS_DEFAULT_DEST =  os.getcwd()
    UPLOADS_DEFAULT_URL = 'http://localhost:9419/static/img/'
    UPLOADED_IMAGES_DEST =  os.getcwd()
    UPLOADED_IMAGES_URL = 'http://localhost:9419/static/img/'

应用程序/初始化.py



from app import app
from flask import Flask
from flask_debug import Debug
from config import Config
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_login import LoginManager, UserMixin, login_required, login_user, logout_user
#from flask.ext.login import LoginManager
from flask_uploads import UploadSet, IMAGES, configure_uploads
#from flask_session import Session
from flask_kvsession import KVSessionExtension
from simplekv.memory.redisstore import RedisStore
import redis
from flask_mail import Mail, Message
from flask import Flask, jsonify, request
from flask_restful import Resource, Api
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
from celery import Celery


store = RedisStore(redis.StrictRedis())

app = Flask(__name__)
app.config.from_object(Config)
app.config['SQLALCHEMY_DATABASE_URI']='mysql://root:redhat@192.168.56.107:3306/flaskdb'
app.config['UPLOADS_DEFAULT_DEST'] =  'app/static/img/'
#app.config['UPLOADED_PHOTO_DEST'] = './app/static/img/'
db = SQLAlchemy(app)
migrate = Migrate(app, db)
login = LoginManager(app)
mail= Mail(app)
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
mail = Mail(app)
api = Api(app)
ma = Marshmallow(app)

#########

## Celery

app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379/0'
app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379/0'
celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)

# #from flask.ext.restless import APIManager
# from flask import Flask
# from flask.ext.restless import APIManager
# from flask.ext.sqlalchemy import SQLAlchemy
#
# #import flask.ext.restless
# manager = flask.ext.restless.APIManager(app, flask_sqlalchemy_db=db)


login.login_view = 'login'

#sess = Session()
#sess.init_app(app)
#KVSessionExtension(store, app)

# Configure the image uploading via Flask-Uploads
#app.config['UPLOADED_PHOTOS_DEST'] = '/var/uploads'
#app.config['UPLOADED_DOCUMENTS_DEST'] = './app//static/img'
#print os.getcwd()

images = UploadSet('images', IMAGES)
configure_uploads(app, images)

Debug(app)
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=9419, debug=True)
#    app.run(debug=True)


from app import routes, models
4

1 回答 1

0

错误消息清楚地表明您尚未为上传配置目标。

你可以看看源代码这个错误是如何发生的。

https://github.com/jugmac00/flask-reuploaded/blob/80654e1c9909025c894cddff940cccfbe9c042d7/src/flask_uploads/flask_uploads.py#L73-L84

当我从上面查看您的代码时...您定义了一个配置类,但您没有使用它,并且您还配置了许多Flask-Uploads相关选项,但是您将它们注释掉了

=> Flask-Uploads,尤其是目的地没有配置

于 2021-04-15T20:09:37.027 回答