def create_post(): user_id = get_jwt_identity() post = BlogPost.from_json(request.json, user_id) db.session.add(post) db.session.commit() return jsonify(post.to_json()), 201
def create_post(): form = BlogPostForm() if form.validate_on_submit(): blog_post = BlogPost(title=form.title.data, text=form.text.data, user_id=current_user.id) db.session.add(blog_post) db.session.commit() flash('Blog post created') return redirect(url_for('core.index')) return render_template('create_post.html', form=form)
def create_post(): form = BlogPostForm() if form.validate_on_submit(): # INSTANCE OF BLOGPOST blog_post = BlogPost(title=form.title.data, text=form.text.data, user_id=current_user.id) # SAVE TO DATABASE db.session.add(blog_post) db.session.commit() flash('Post Created') return redirect(url_for('core.index')) return render_template('create_post.html', form=form)
def create_post(): form = BlogPostForm() print("Came here") if form.validate_on_submit(): print("I qm Here") blog_post = BlogPost(title = form.title.data, text = form.text.data, user_id = current_user.id) db.session.add(blog_post) db.session.commit() flash('Blog Post Created') return redirect(url_for('core.index')) elif request.method == 'GET': print("This error") else: print("errored") return render_template('create_post.html',form = form)