def post_photo(username, album_id): user = User.query.filter_by(username=username).first() album = Album.query.filter_by(id=album_id).first() form = PhotoForm() if request.method == 'POST' and form.validate(): new_photo = Photo(caption=form.caption.data, image=form.image.data, album_id=album.id) db.session.add(new_photo) db.session.commit() flash('Photo successfully uploaded') return redirect(url_for('photos', username=username, album_id=album_id)) return render_template('new_photo.html', user=user, album=album, form=form)