def create(): if request.method == "POST": form = SnippetForm(request.form) if form.validate(): snippet = form.save_entry(Snippet()) db.session.add(snippet) db.session.commit() return redirect(url_for("snippets.detail", slug=snippet.slug)) else: form = SnippetForm() return render_template("snippets/create.html", form=form)
def create(): if request.method == 'POST': form = SnippetForm(request.form) if form.validate(): snippet = form.save_entry(Snippet()) db.session.add(snippet) db.session.commit() return redirect(url_for('snippets.detail', slug=snippet.slug)) else: form = SnippetForm() return render_template('snippets/create.html', form=form)
def edit(slug): snippet = Snippet.query.filter(Snippet.slug == slug).first_or_404() if request.method == "POST": form = SnippetForm(request.form, obj=snippet) if form.validate(): snippet = form.save_entry(snippet) db.session.add(snippet) db.session.commit() return redirect(url_for("snippets.detail", slug=entry.slug)) else: form = EntryForm(obj=entry) return render_template("entries/edit.html", entry=snippet, form=form)
def edit(slug): snippet = Snippet.query.filter(Snippet.slug == slug).first_or_404() if request.method == 'POST': form = SnippetForm(request.form, obj=snippet) if form.validate(): snippet = form.save_entry(snippet) db.session.add(snippet) db.session.commit() return redirect(url_for('snippets.detail', slug=entry.slug)) else: form = EntryForm(obj=entry) return render_template('entries/edit.html', entry=snippet, form=form)