flask request Example Python Code

The Flask request (source code) object is critical for building web applications with this web framework. The request context allows you to obtain data sent from the client such as a web browser so that you can appropriately handle generating the response.

Example 1 from FlaskBB

FlaskBB (project website) is a Flask-based forum web application. The web app allows users to chat in an open message board or send private messages in plain text or Markdown. FlaskBB is provided as open source under this license.

flaskbb / flaskbb / app.py

# -*- coding: utf-8 -*-
    manages the app creation and configuration process
    :copyright: (c) 2014 by the FlaskBB Team.
    :license: BSD, see LICENSE for more details.
import logging
import logging.config
import os
import sys
import time
import warnings
from datetime import datetime

from flask import Flask, request
from flask_login import current_user
from sqlalchemy import event
from sqlalchemy.engine import Engine
from sqlalchemy.exc import OperationalError, ProgrammingError

## ... code abbreviated here due to several hundred non-relevant lines ...

def configure_before_handlers(app):
    """Configures the before request handlers."""

    def update_lastseen():
        """Updates `lastseen` before every reguest if the user is
        if current_user.is_authenticated:
            current_user.lastseen = time_utcnow()

    if app.config["REDIS_ENABLED"]:

        def mark_current_user_online():
            if current_user.is_authenticated:
                mark_online(request.remote_addr, guest=True)


Full Stack Python

Full Stack Python is an open book that explains concepts in plain language and provides helpful resources for those topics.
Updates via Twitter & Facebook.

Matt Makai 2012-2022