def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data, author=current_user) db.session.add(post) db.session.commit() flash('Your Post has been created!', 'success') return redirect(url_for('home')) return render_template('create_post.html', title='New Post', form=form, legend='New Post')
def create_page(): form = CreateForm() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data, writer=current_user) db.session.add(post) db.session.commit() flash('post has been created successfully') return redirect(url_for('blog.home_page')) return render_template('post/create.html', form=form)
def debug_add_post(): json_path = os.path.join(app.root_path, 'static', 'posts.json') with open(json_path) as json_file: data = json.load(json_file) for post_data in data: author = User.query.get(post_data['user_id']) post = Post(title=post_data['title'], content=post_data['content'], author=author) db.session.add(post) db.session.commit() flash("Posts have been added!", "success") return redirect(url_for('home'))
def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, information=form.information.data, name=current_user.username, admin=current_user, user_id=current_user.id) db.session.add(post) db.session.commit() flash("New post created!", 'success') return redirect(url_for('home')) return render_template('create_post.html', title='New Post', legend='New Post', form=form)
6 @app.route("/debug_add_posts") 7 def debug_add_post(): 8 json_path = os.path.join(app.root_path, 'static', 'posts.json') 9 with open(json_path) as json_file: 10 data = json.load(json_file) 11 for post_data in data: 12 author = User.query.get(post_data['user_id']) 13 post = Post(title=post_data['title'], content=post_data['content'], author=author) 14 db.session.add(post) 15 db.session.commit() 16 flash("Posts have been added!", "success") 17 return redirect(url_for('home'))