Пример #1
0
def post_blog():
	form = BlogForm()
	if form.validate_on_submit():
		blog = form.get_blog()
		mongo.db.blogs.insert(blog)
		flash('发布成功')
		return redirect(request.args.get('next') or url_for('main.index'))

	return render_template('post.html', form=form)
Пример #2
0
def edit_blog(blog_id):
	blog = mongo.db.blogs.find_one_or_404({'_id': ObjectId(blog_id)})
	form = BlogForm(data=blog)
	if form.validate_on_submit():
		formdata = form.get_blog()
		formdata.pop("time")
		formdata.pop("view_count")
		mongo.db.blogs.update({"_id": ObjectId(blog_id)}, {"$set": formdata}, True, False)
		flash('更新成功')
		return redirect(request.args.get('next') or url_for('main.index'))
	return render_template('post.html', form=form)