def blog_create(): form = BlogForm() blog = Blog(user_id=g.user.id, user_name=g.user.name, user_image=g.user.image) if form.validate_on_submit(): blog.name = form.name.data.strip() blog.summary = form.summary.data.strip() blog.content = form.content.data.strip() rownumber = blog.save() if rownumber != 1: return render_template('blog_edit.html', user=g.user, form=form, blog=blog) return redirect(url_for('blog_manage')) return render_template('blog_edit.html', user=g.user, form=form, blog=blog)
def blog_edit(id): form = BlogForm() blog = Blog.find(id) blog.content = blog.content.replace('\r', '\\r').replace('\n', '\\n') blog.summary = blog.summary.replace('\r', '\\r').replace('\n', '\\n') if form.validate_on_submit(): blog.name = form.name.data.strip() blog.summary = form.summary.data.strip() blog.content = form.content.data.strip() rownumber = blog.update() if rownumber != 1: return render_template('blog_edit.html', user=g.user, form=form, blog=blog) return redirect(url_for('blog_manage')) return render_template('blog_edit.html', user=g.user, form=form, blog=blog)