def upload(): if request.method == 'POST' and 'photo' in request.files: filename = photos.save(request.files['photo']) print filename current_user.set_avatar('/static/uploads/'+filename) flash("Photo saved.") #return redirect("/user/settings") return render_template('upload.html')
def retrieve_data(): print('syncing ', current_user.username) current_user.update_sections() current_user.update_assignments() current_user.update_events() current_user.set_avatar() current_user.update_grades() flash('All synced up!') return render_template('sync.html')
def upload_avatar(): try: if 'avatar' in request.files: avatar_name = avatars.save(request.files['avatar']) # 上传的图片的 url 地址为: /_uploads/avatars/filename.png avatar_url = avatars.url(avatar_name) current_user.set_avatar(avatar_name) flash('Upload avatar successfully!', 'success') except Exception as e: flash('Please choose an image before upload.', 'warning') return redirect(url_for('settings_bp.index'))
def set_avatar(): """ Set a user avatar """ file = request.files['file'] if not file or not Image.allowed_file(file.filename): return render_template('settings.html', error={'avatar': 'Invalid image'}) current_user.set_avatar(file) user_needs_refresh.send(current_app._get_current_object()) return render_template('settings.html')