Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14185

ValueError: not enough values to unpack (expected 3, got 2) for thumbnail_size = ((100, 100), PIL.Image.Resampling.LANCZOS))

$
0
0

I had an AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS' error for uplaoding an image on Flask Admin. I corrected it to thumbnail_size = ((100, 100), PIL.Image.Resampling.LANCZOS)). Now the line is giving me the ValueError: not enough values to unpack (expected 3, got 2).The code is;

import osimport os.path as opfrom flask import Flask, url_forfrom flask_sqlalchemy import SQLAlchemyfrom markupsafe import Markupfrom flask_admin import Admin, formfrom flask_admin.contrib import sqla, redisclifrom PIL import Imageimport PILapp = Flask(__name__, static_folder='files')# see http://bootswatch.com/3/ for available swatches themesapp.config['FLASK_ADMIN_SWATCH'] = 'cerulean'# Create dummy secrey key so we can use sessionsapp.config['SECRET_KEY'] = '123456790'# Create in-memory databaseapp.config['DATABASE_FILE'] = 'sample_db.sqlite'app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+ app.config['DATABASE_FILE']app.config['SQLALCHEMY_ECHO'] = Truedb = SQLAlchemy(app)# Create directory for file fields to usefile_path = op.join(op.dirname(__file__), 'files')try:    os.mkdir(file_path)except OSError:    passclass Image(db.Model):    id = db.Column(db.Integer, primary_key=True)    name = db.Column(db.Unicode(64))    path = db.Column(db.Unicode(128))    def __unicode__(self):        return self.nameclass ImageView(sqla.ModelView):    def _list_thumbnail(view, context, model, name):        if not model.path:            return ''        return Markup('<img src="%s">' % url_for('static',                                                 filename=form.thumbgen_filename(model.path)))    column_formatters = {'path': _list_thumbnail    }    # Alternative way to contribute field is to override it completely.    # In this case, Flask-Admin won't attempt to merge various parameters for the field.    form_extra_fields = {'path': form.ImageUploadField('Image',                                      base_path=file_path,                                      #thumbnail_size=(100, 100, True))                                      thumbnail_size = ((100, 100), PIL.Image.Resampling.LANCZOS))    }# Flask views@app.route('/')def index():    return '<a href="/admin/">Click me to get to Admin!</a>'# Create adminadmin = Admin(app, 'Example: Forms', template_mode='bootstrap4')# Add viewsadmin.add_view(ImageView(Image, db.session))def build_sample_db():    db.create_all()    db.session.commit()    returnif __name__ == '__main__':    # Build a sample db on the fly, if one does not exist yet.    app_dir = op.realpath(os.path.dirname(__file__))    database_path = op.join(app_dir, app.config['DATABASE_FILE'])    if not os.path.exists(database_path):        with app.app_context():            build_sample_db()    # Start app    app.run(debug=True)

I was expecting to be able to upload an image from Flask Admin using the specified path


Viewing all articles
Browse latest Browse all 14185

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>