

We are also providing default values in case environment variables are not set. get ( 'PRODUCTION_DATABASE_URI' ) or that for the first time we are reading values of some configurations from the environment variables. get ( 'TESTING_DATABASE_URI' ) or class ProductionConfig ( BaseConfig ): DEBUG = False SQLALCHEMY_DATABASE_URI = os. get ( 'DEVELOPMENT_DATABASE_URI' ) or class TestingConfig ( BaseConfig ): DEBUG = True SQLALCHEMY_DATABASE_URI = os. get ( 'MAIL_PASSWORD' ) or 'password' MAIL_DEFAULT_SENDER = MAIL_USERNAME class DevelopementConfig ( BaseConfig ): DEBUG = True SQLALCHEMY_DATABASE_URI = os. get ( 'MAIL_USERNAME' ) or MAIL_PASSWORD = os. get ( 'SECRET_KEY' ) or 'A SECRET KEY' SQLALCHEMY_TRACK_MODIFICATIONS = False # Flask-Mail configurations # MAIL_SERVER = '' MAIL_PORT = 587 MAIL_USE_TLS = True MAIL_USERNAME = os. dirname ( _file_ )) class BaseConfig : SECRET_KEY = os.
FLASK BLUEPRINT EXAMPLE CODE
The environment-specific classes can override or add environment-specific configurations.Ĭreate a new file named config.py inside flask_app directory and add the following code in it: Start off by defining default configurations in the base class and then create environment-specific classes which inherit from the base class. We can implement such a configuration system using classes. You will also notice that no matter which environment you are in some configurations always remains the same.
FLASK BLUEPRINT EXAMPLE SOFTWARE
Class-Based Configurations #Ī software project usually runs in three different environments:Īs the project evolves you will encounter a need to specify different configuration options for different environment. In the rest of the lesson, we will convert our project to conform to this directory structure. The entry point for your Flask application. The config.py contains settings and configuration for your Flask application.

The views.py contains routes and view functions. The templates directory contains templates. The static directory contains the static files of the project. The _init_.py tells the Python that app directory is a Python package. The app directory is a Python package which holds views, templates, and static files. Example: ```python bp = APIBlueprint('foo', _name_, tag='Foo') ``` ```python bp = APIBlueprint('foo', _name_, tag=`) for `json` location.The app_dir is the root directory of your Flask project. Accepts a tag name string or an OpenAPI tag dict. If not set, the `.title()` will be used (`'foo'` -> `'Foo'`). This helps locate the `root_path` for the blueprint. import_name: The name of the blueprint package, usually `_name_`.

Arguments: name: The name of the blueprint. Union ] = _sentinel # type: ignore ) -> None : """Make a blueprint instance. Optional ] = None, enable_openapi : bool = True, static_folder : t. *Version added: 0.2.0* """ def _init_ ( self, name : str, import_name : str, tag : t.

Examples: ```python from apiflask import APIBlueprint bp = APIBlueprint('foo', _name_) ``` *Version changed: 0.5.0* - Add `enable_openapi` parameter. Class APIBlueprint ( APIScaffold, Blueprint ): """Flask's `Blueprint` object with some web API support.
