D74 and D75 #100DaysOfCode

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.

code-capture

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!

code-capture

Written on December 4, 2019