Picturedata picturefile currentuserusername

  • No School
  • AA 1
  • DoctorHawk12736
  • 3
  • 100% (1) 1 out of 1 people found this document helpful

This preview shows page 2 - 3 out of 3 pages.

picture_file = save_picture(form.picture.data)current_user.image_file = picture_filecurrent_user.username = form.username.datacurrent_user.email = form.email.datadb.session.commit()flash('Your account has been updated!', 'success')return redirect(url_for('account'))elif request.method == 'GET':form.username.data = current_user.usernameform.email.data = current_user.emailimage_file = url_for('static', filename='profile_pics/' + current_user.image_file)return render_template('account.html', title='Account',image_file=image_file, form=form)@app.route("/post/new", methods=['GET', 'POST'])@login_requireddef 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')@app.route("/post/<int:post_id>")def post(post_id):post = Post.query.get_or_404(post_id)return render_template('post.html', title=post.title, post=post)
Background image
@app.route("/post/<int:post_id>/update", methods=['GET', 'POST'])@login_requireddef update_post(post_id):post = Post.query.get_or_404(post_id)if post.author != current_user:abort(403)form = PostForm()if form.validate_on_submit():post.title = form.title.datapost.content = form.content.datadb.session.commit()flash('Your post has been updated!', 'success')return redirect(url_for('post', post_id=post.id))elif request.method == 'GET':form.title.data = post.titleform.content.data = post.contentreturn render_template('create_post.html', title='Update Post',form=form, legend='Update Post')@app.route("/post/<int:post_id>/delete", methods=['POST'])@login_requireddef delete_post(post_id):post = Post.query.get_or_404(post_id)if post.author != current_user:abort(403)db.session.delete(post)db.session.commit()flash('Your post has been deleted!', 'success')return redirect(url_for('home'))
Background image

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture