user.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:forum 作者: ElfenSterben 项目源码 文件源码
def upload_avatar():
    u = g.user
    if 'photo' in request.files:
        form = request.form
        filename = str(uuid3(NAMESPACE_DNS, str(u.id) + u.username + str(time.time()))).replace('-','')
        try:
            x = int(form['x'])
            y = int(form['y'])
            w = int(form['nw'])
            h = int(form['nh'])
            img = Image.open(request.files['photo'])
            format = img.format
            croped_img = crop_img(img, x, y, w, h)
            filename = save_avatar(croped_img, filename, format)
            url_path = current_app.config['UPLOADED_PHOTOS_URL']
            old_name = u.avatar.split(url_path)[1]
            remove_avatar(old_name)
            u.avatar = url_path + filename
            u.save()
        except Exception as e:
            print(e)
            flash('????????2Mb?????', 'error')
    return redirect(url_for('user.setting_view'))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号