Beispiel #1
0
def add():
    """ 新增文章 """
    form = BlogsForm()
    if form.validate_on_submit():
        blog = Blogs(
            title=form.title.data,
            content=form.content.data,
            types=form.types.data,
            images=form.images.data,
            is_valid=True,
            create_time=datetime.now(),
            update_time=datetime.now(),
        )
        db.session.add(blog)
        db.session.commit()
        flash('添加成功')
        return redirect(url_for('admin'))
    return render_template('/admin/add.html', form=form)
Beispiel #2
0
def update(pk):
    """ 更新文章 """
    obj = Blogs.query.get(pk)
    if obj is None:
        abort(404)
    form = BlogsForm(obj=obj)
    if form.validate_on_submit():
        blog = Blogs(
            title=form.title.data,
            content=form.content.data,
            types=form.types.data,
            images=form.images.data,
            update_time=datetime.now(),
        )
        db.session.add(blog)
        db.session.commit()
        flash('修改成功')
        return redirect(url_for('admin'))
    return render_template('/admin/update.html', form=form)