def edit_bookmark(bookmark_id): bookmark = Bookmark.query.get_or_404(bookmark_id) if current_user != bookmark.user: abort(403) form = BookmarkForm(obj=bookmark) # fill form with the data from the database if form.validate_on_submit(): form.populate_obj(bookmark) # copy form data into bookmark db.session.commit() # bookmark object is already in the session since we made a get flash('Stored "{}"'.format(bookmark.description)) return redirect(url_for('user', username=current_user.username)) return render_template('bookmark_form.html', form=form, title= "Edit bookmark")
def add(): # if get, form is empty, but if post, form has data form = BookmarkForm() # if request.method == "POST": if form.validate_on_submit(): # url = request.form['url'] url = form.url.data description = form.description.data bm = Bookmark(user=current_user, url=url, description=description) db.session.add(bm) db.session.commit() flash('Stored {0}'.format(description)) return redirect(url_for('index')) return render_template("add.html", form=form)