def addpost(): form = PostForm(request.form) if request.method == 'POST' and form.validate_on_submit(): title = form.title.data content = form.content.data tags = normalize_tags(form.tags.data) entry = Post(title=title, content=content) entry.tags = tags try: entry.store_to_db() flash(u'文章存入成功') except: flash(u'文章存入失败,请与管理员联系') return redirect(url_for('admin.index')) return render_template('admin/addpost.html', form=form)