D74 and D75 #100DaysOfCode

D74 and D75 #100DaysOfCode. I have implemented a user profile page as well as a couple other features! I might actually know what I’m doing,

Read Time1 Minute, 5 Seconds

Day 74/75 already! These 100 days are going to be over before I know it.

So the last post I had implemented a way to create an account and enforced having to log in to be able to access the site. I know have implemented a user profile page where the user can edit their name and write a bit about themselves.

I have also added user profile pictures using Gravatar, it adds a nice little touch to the site and saves me having to store a bunch of avatar images.

So this is what the user profile page looks like.

You can see a couple of posts I’ve made, these are static at the moment;

def user(username):
    user = User.query.filter_by(username=username).first_or_404()
    posts = [
        {'author': user, 'body': 'Test post #1'},
        {'author': user, 'body': 'Test post #2'}
    ]
    return render_template('user.html', user=user, posts=posts)

Another new feature is being able to see when the user was last active, this is using a flask function called “before_request”;

@app.before_request
def before_request():
    if current_user.is_authenticated:
        current_user.last_seen = datetime.utcnow()
        db.session.commit()

So before any route is called this one is called first and updates the user’s last_seen column in the database.

Now, let’s see it in action!

0 0
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleppy
Sleppy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

2 thoughts on “D74 and D75 #100DaysOfCode

Leave a Reply

Your email address will not be published. Required fields are marked *

Close