示例#1
0
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)
示例#2
0
文件: blueprint.py 项目: octt/flask
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)
示例#3
0
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)
示例#4
0
文件: blueprint.py 项目: octt/flask
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)