<commit_before>Subclassing Flask
=================

The :class:`~flask.Flask` class is designed for subclassing.

One reason to subclass would be customizing the Jinja2 :class:`~jinja2.Environment`. For example, to add a new global template variable::

    from flask import Flask
    from datetime import datetime

    class MyFlask(Flask):
        """ Flask with more global template vars """

        def create_jinja_environment(self):
            """ Initialize my custom Jinja environment. """
            jinja_env = super(MyFlask, self).create_jinja_environment(self)
            jinja_env.globals.update(
                current_time = datetime.datetime.now()
            )
            return jinja_env

This is the recommended approach for overriding or augmenting Flask's internal functionality.<commit_msg>Rewrite subclassing example with a better use-case.<commit_after>Subclassing Flask
=================

The :class:`~flask.Flask` class is designed for subclassing.

For example, you may want to override how request parameters are handled to preserve their order::

    from flask import Flask, Request
    from werkzeug.datastructures import ImmutableOrderedMultiDict
    class MyRequest(Request):
        """Request subclass to override request parameter storage"""
        parameter_storage_class = ImmutableOrderedMultiDict
    class MyFlask(Flask):
        """Flask subclass using the custom request class"""
        request_class = MyRequest

This is the recommended approach for overriding or augmenting Flask's internal functionality.
{'fraction_non_alphanumeric': 0.0834403080872914, 'fraction_numerical': 0.0012836970474967907, 'mean_word_length': 3.6676646706586826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3686371', 'n_tokens_mistral': 404, 'n_tokens_neox': 374, 'n_words': 144}