Introduction to flash


Statement: the following is my personal understanding. If you find any mistakes or questions, you can contact me for discussion

brief introduction

Flash is a lightweight web development framework written by Armin ronache in 2010 with Python language based on Werkzeug toolbox.


Flash only provides core functions, and almost all other functions need to be expanded. For example, you can operate the database through the expansion of flash Sqlalchemy.


fromWerkzeugAndJinja2The composition of Werkzeug is a comprehensive oneWSGIWeb application library, Jinja is a modern and design friendly Python template language.

Common extensions of flash

Related documents

  1. Chinese document
  2. English document

Flask’s first experience

Install and use virtual environment

Virtualenv create and manage virtual environment


Pipenv creates and manages virtual environments


Install the specified version of flash framework

sudo pip install flask==1.0.2

Create a file and bring it in to write the first flag program


Write the following code in the file

#Import the flash class

Exit edit mode and run the program


You can see the following results

Introduction to flash

This starts a very simple built-in server. This server should be enough for testing, but it may not be enough for production. Now open in the browser127.0.0.1:5000/, you should see Hello flag! word.

Introduction to flash

Related configuration parameters

Initialization parameters

The first step to create a flag project is to instantiate the flag object. The following is a detailed explanation of the parameters required to instantiate the object

  • import_ Name: the package (module) where the flag program is located__name__Can,

  • static_ url_ Path: static file access path, can not be transferred, the default is:/ + static_folder

  • static_ Folder: static file storage folder, can not be transferred, the default isstatic

  • static_ Host: use the address of the remote host to store the static file. The default is none. When host_ When matching is true, you can use static_ Folder configures the folder where static files are stored

  • host_ Matching: settingurl_map.host_matchingProperty, which is false by default

  • subdomain_ Matching: when matching routes, consider the subdomains associated with: data: ` server_ NAME’。 The default is false.

  • template_ Folder: the folder where the template file is stored. It can not be transferred. The default value istemplates

  • instance_ Path: by default, the alternate instance path of the application assumes the folder “instance” next to the package or module as the instance path.

  • instance_ relative_ Config: if the relative file name used to load the configuration is set to true, it is assumed that the file name is relative to the instance path rather than the application root.

  • root_ Path: by default, flag automatically calculates the application root path. In some cases, this is not possible (for example, if the package is a python 3 namespace package) and needs to be defined manually.

Program loading configuration

Before running the flash program, we can set the relevant configuration for the flash, such as env (application running in what environment), debug (enable debugging mode) and testing (enable test mode). There are two common ways to achieve this

  • Load from configuration file:app.config.from_pyfile()

    Create a configuration file

    touch config.ini
    vim config.ini

    Write configuration information

    DEBUG = True

    Select load from configuration file

    #Create a flash class object to point to the name of the package where the program is located
  • Load from configuration object: app.config.from_ object()

    Create a configuration class and pass in the class name

    #Configuration class

Program running configuration

In this demo, the entry to start the flash project is app. Run(). The common configuration options are host, port and debug. They are to set the IP address and port number of the running host, and whether to open the debugging mode. When there are debugs in the configuration file and here, the debug here will prevail."", port=8000)


In web development, routing is a program that forwards URLs to corresponding views.

This work adoptsCC agreementReprint must indicate the author and the link of this article

Recommended Today

What is “hybrid cloud”?

In this paper, we define the concept of “hybrid cloud”, explain four different cloud deployment models of hybrid cloud, and deeply analyze the industrial trend of hybrid cloud through a series of data and charts. 01 introduction Hybrid cloud is a computing environment that integrates multiple platforms and data centers. Generally speaking, hybrid cloud is […]