本文整理汇总了Python中blog.forms.PostForm.validate_on_submit方法的典型用法代码示例。如果您正苦于以下问题:Python PostForm.validate_on_submit方法的具体用法?Python PostForm.validate_on_submit怎么用?Python PostForm.validate_on_submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.forms.PostForm
的用法示例。
在下文中一共展示了PostForm.validate_on_submit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_post
# 需要导入模块: from blog.forms import PostForm [as 别名]
# 或者: from blog.forms.PostForm import validate_on_submit [as 别名]
def new_post():
form = PostForm()
if form.validate_on_submit():
post = Post(title = form.title.data,
content = form.content.data,
author = users.get_current_user())
post.put()
flash('Post saved on database.')
return redirect(url_for('list_posts'))
return render_template('new_post.html', form=form)
示例2: edit_post
# 需要导入模块: from blog.forms import PostForm [as 别名]
# 或者: from blog.forms.PostForm import validate_on_submit [as 别名]
def edit_post(slug):
''' Post edit view of admin panel '''
post = Post.objects(slug=slug)[0]
form = PostForm(request.form, obj=post)
if request.method == 'POST' and form.validate_on_submit():
post.title = request.form.get('title')
post.author = form.author.data
if request.form.get('new_tags'):
new_tags = process_tags(request.form['new_tags'])
post.tags = new_tags
post.index_background = form.index_background.data
post.category = form.category.data
post.published = form.published.data
post.content = request.form.get('content')
post.save()
flash('Post has been edited')
return redirect(url_for('posts.edit_post', slug=post.slug))
return render_template("/admin/edit_post.html", form=form, slug=slug)
示例3: new_post
# 需要导入模块: from blog.forms import PostForm [as 别名]
# 或者: from blog.forms.PostForm import validate_on_submit [as 别名]
def new_post():
''' Create new post from admin view. '''
form = PostForm(request.form)
if request.method == 'POST' and form.validate_on_submit():
post_args = {}
if Post.objects(title=form.title.data):
flash("Post with this title already exists!")
return render_template('/admin/new_post.html', form=form)
if request.form.get('new_tags'):
post_args['tags'] = process_tags(request.form.get('new_tags'))
post_args['index_background'] = form.index_background.data
post_args['published'] = form.published.data
post_args['title'] = form.title.data
post_args['author'] = form.author.data
post_args['content'] = form.content.data
post_args['category'] = form.category.data
new_post = Post(**post_args)
new_post.save()
flash("New post, '{}', successfully created!".format(new_post.title))
return redirect(url_for('posts.edit_post', slug=new_post.slug))
return render_template('/admin/new_post.html', form=form)