Flask Request Object - Sender's IP Address


In Flask, the request object can be used to log the IP address of the sender using request.remote_addr.

👇

@users_blueprint.route('/login')
def login():
    if request.method == 'POST':
        # Log in the user
        current_app.logger.info(
            f'New login request from from IP address: {request.remote_addr}'
        )
        return '<p>User logged in!</p>'

    return '<h2>Login Form</h2>'