def create_post(): form = BlogPostForm() if form.validate_on_submit(): if form.image.data: image = add_image_pic(form.image.data) s3_resource = boto3.resource('s3') my_bucket = s3_resource.Bucket(app.config['AWS_BUCKET']) my_bucket.Object(image).put(Body=form.image.data) test = 'https://' + str(app.config['AWS_BUCKET'] ) + '.s3-ap-northeast-1.amazonaws.com/{}' images = test.format(image) blog_post = BlogPost(title=form.title.data, event_date=form.event_date.data, event_time=form.event_time.data, text=form.text.data, organizer=form.organizer.data, place=form.place.data, entry=form.entry.data, way=form.way.data, cost=form.cost.data, contact=form.contact.data, user_id=current_user.id, event_image=images) else: blog_post = BlogPost( title=form.title.data, event_date=form.event_date.data, event_time=form.event_time.data, text=form.text.data, organizer=form.organizer.data, place=form.place.data, entry=form.entry.data, way=form.way.data, cost=form.cost.data, contact=form.contact.data, user_id=current_user.id, event_image='https://' + str(app.config['AWS_BUCKET']) + '.s3-ap-northeast-1.amazonaws.com/default_profile.png') db.session.add(blog_post) db.session.commit() flash("投稿を作成しました!") return redirect(url_for('core.index')) return render_template('create_post.html', form=form, api=str(app.config['GOOGLE_MAP_API']))
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(): # Instance of form 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(): """Creates a blog post""" form = BlogPostForm() if form.validate_on_submit(): blog_post = BlogPost(title=form.title.data, text=form.text.data, user_id=current_user.id, slug=form.title.data.strip().lower().replace( ' ', '-')) db.session.add(blog_post) db.session.commit() # creates and/or connects inputed tags with the post tags_from_string(form.tags.data, blog_post) flash('Blog post successfully created!', 'success') return redirect(url_for('core.index')) return render_template('create_post.html', form=form)
def create_post(): form = PostForm() if form.validate_on_submit(): blog_post = BlogPost(title=form.heading.data, text=form.post.data, user_id=current_user.id, keywords=form.keywords.data, meta_title=form.meta_title.data, meta_desc=form.meta_desc.data, category=form.category.data) 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)