def article_create(): form = ArticleCreateForm() form.category_id.choices = Category.choices() if request.method == 'POST' and form.validate(): if not g.user.is_admin(): flash(u'非管理员不能创建文章!') return redirect(url_for('index')) else: nowtime = datetime.datetime.now() article = Article(title=form.title.data, body=form.body.data, user_id=g.user.id, category_id=form.category_id.data, text=request.form.get('textformat'), timestamp=nowtime, tag=form.tag.data, is_open=form.is_open.data) article.post_date = nowtime db.session.add(article) db.session.commit() flash(u'文章已创建!') Blog_info.new_article() return redirect(url_for('article_edit', id=article.id)) return render_template('article_create.html', title=u'创建文章', form=form)