예제 #1
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(title=form.title.data,
                    content=form.content.data,
                    author=current_user)
        if form.image.data:
            picture_file = save_picture(form.image.data)
            post.image = picture_file
        db.session.add(post)
        db.session.commit()
        flash('Your post has been published.', 'success')
        return redirect(url_for('main.home'))
    return render_template('create_post.html',
                           title='New Post',
                           form=form,
                           legend='New Post',
                           prof_pic=firebase_storage.prof_img(current_user))
예제 #2
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        if form.img.data:
            picture_file = subir_foto(form.img.data)
            post = Post(title=form.title.data, content=form.content.data, author=current_user, image=picture_file)
            post.image = picture_file
            db.session.add(post)
            db.session.commit()
            flash('Posteado con exito', 'success')
            return redirect(url_for('home'))
        else:
            post = Post(title=form.title.data, content=form.content.data, author=current_user)
            db.session.add(post)
            db.session.commit()
            flash('Posteado con exito', 'success')
            return redirect(url_for('home'))
    return render_template('create_post.html', title='Nuevo Post', form=form, legend='Nuevo Post')