当前位置: 首页>>代码示例>>Python>>正文


Python PostForm.validate_on_submit方法代码示例

本文整理汇总了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)
开发者ID:LubergAlexander,项目名称:google-cloud-flask,代码行数:12,代码来源:views.py

示例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)
开发者ID:LiYChristopher,项目名称:Outpost,代码行数:21,代码来源:posts.py

示例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)
开发者ID:LiYChristopher,项目名称:Outpost,代码行数:23,代码来源:posts.py


注:本文中的blog.forms.PostForm.validate_on_submit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。