Python Flask Tutorial: Full-Featured Web App Part 7 - User Account and Profile Picture
Why Stack Overflow recommends it
Stack Overflow users link it when answering or asking about Flask account update forms, saving uploaded profile images, and WTForms validation, since it walks through exactly that code.
Recommended by 3 people across 3 different months, 2019 to 2023.
What it is
Part 7 of Corey Schafer's Flask series finishes the user account page so users can update their username and email, then adds profile picture upload with image resizing (using Pillow) to save server space. It is a 42-minute follow-along coding tutorial building on the earlier parts of the Flask blog app.
What people said
Strong rec WISERDIVISOR · 2020-11 · Stack Overflow · on “How to upload an image with flask-admin and flask-sqlachelmy?”
You are on the right path. Somewhat... It will be a db.String column and it will store the path of the image file. When you want to display the image on your page, it will be using url_for() or url() and using the <img> tag. It will look something like this :: In the route : image_file = url_for('static', filename='coverpics/'+current_user.cover) return render_template(#your other args..., cover_url=image_file) Here, current_user is to automatically fetch the current logged in user and then make any DB queries you want related to that user. In the template : <img href="{{cover_url}}"> But since you are an absolute beginner, I assume that you don't even know how to save the uploaded cover pic
Recommends monge1h · 2019-03 · Stack Overflow · on “Update password form with hashing flask application”
Yes, you can do that with wtforms and sqlalchemy class UpdateAccountForm(FlaskForm): username = StringField('Username', validators=[DataRequired(), Length(min=2,max=20)]) email = StringField('Email', validators=[DataRequired(), Email()]) submit = SubmitField('Update') @app.route("/account" , methods=['GET','Post']) @login_required #This is from flask-login extension def account(): form = UpdateAccountForm() if form.validate_on_submit(): current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Your account has been updated') return redirect(url_for('account')) elif request.method == 'GET': form.username.data = current_user.username form.email.
Recommends Rehman Arshad · 2021-08 · Stack Overflow · on “Im thinking of making a webapp with django, that's basically a wallpaper generator, but where to store and how to display an image on heroku?”
Here is an idea: Start with something simple, like an sqlite3 database on localhost, (no AWS needed), get pillow to store the image within a particular specified directory, and store the relative directory path to the image on sqlite3, such that a variable can be assigned such (a string that contains) the path to the file and be injected into the src component of an img tag. As such: <img src="{{ variable_name }}" > actually on the subject of randomness this might be a better way to display images using JINJA templating: <img src="{{ directory_path }}/{{ random_image_number }} "> From here it's matter of just manipulating the variable to randomly pick different files from where the all image
Cites kakashiz yo · 2023-05 · Stack Overflow · on “I want my ValidationError to say "username already taken," but I get an Integrity Error(Flask)”
Below is the registration form python file: I'm following a tutorial by Corey Shafer: [this video] , and I basically followed every step so far, except for the bootstrap. How can I return "username already taken" when I try to sign up with the same username? I'm not exactly sure what to do, looked up a bunch of answers but haven't really found anything. from flask_wtf import FlaskForm from wtforms import StringField, PasswordField, SubmitField, BooleanField from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError from flask_pract.models import User class Reg_Form(FlaskForm): username = StringField('Username', validators=[DataRequired(),Length(min=5,max=20)]) email = St