def upload(): form = UploadForm() if form.validate_on_submit(): video = Video(title=form.title.data, description=form.description.data, user=current_user) db.session.add(video) db.session.flush() f = form.upload.data filename = secure_filename(f.filename) f1, ext = os.path.splitext(filename) path = os.path.join(basedir, "app/static", str(video.id)) + ext f.save(path) video.path = "/static/" + str(video.id) + ext db.session.commit() # video.path = path # db.session.add flash('Congratulations, your video has been uploaded!') return redirect(url_for('watch', video_id=video.id)) return render_template('upload.html', title='Upload', form=form)