def test(): form = ImageForm() image = Image() if form.validate_on_submit(): if form.photo.data: picture_file = save_picture(form.photo.data) image.image_file = picture_file image.name = form.name.data db.session.add(image) db.session.commit() #image_file = url_for('static', filename='img' + image_f) return render_template('image.html', form=form)
def upload_file(): image = Image() form = ImageForm( ) #The request method brings about the frontend error in the template file ie "No file was chosen" if form.validate_on_submit(): filename = photos.save(form.photo.data) file_url = photos.url(filename) f_name, f_ext = os.path.splitext(filename) picture_fn = f_name + f_ext picture_path = os.path.join(app.root_path, 'static/profile_pics', picture_fn) image.image_file = picture_fn #Dont forget to change the image path if it workd later on image.name = form.name.data db.session.add(image) db.session.commit() else: file_url = None return render_template('image_final.html', form=form, file_url=file_url)