1, the preface

Flask: I learn the Flask by watching MOOCs videos, and I blog here to take notes and reinforce what I've learned.Copy the code

2. Tool download

  • PyCharm is used in the development tool
  • To download Python3.6, go to the Python website
  • Download MAMP, mainly using Mysql

3. Environment construction

Since I use a MAC, I only focus on how it works on the MAC.Copy the code
  • To check whether PIp3 is installed, enter PIP3 on the terminal
  • If pip3 is installed and virtualenv is installed, enter
 pip3 install virtualenv
Copy the code
  • Building a Virtual Environment
virtualenv venv
Copy the code
  • Running a virtual environment
source /Users/wyhaiapple/Desktop/venv/bin/activate 
Copy the code
  • Check to see if anything is installed in the virtual environment
pip3 freeze
Copy the code
  • Install the flask
pip3 install flask
Copy the code
  • Exiting a Virtual Environment
deactivate
Copy the code

The above is the construction of the environment, if all can prove that the environment is good

Flask’s first little Demo

  • Open pyCharm and create the project

Virtualenv can be selected directly here

  • Check whether Flask is installed

    Then select the following image in Preferences. This image is displayed after adding Flask. If you don’t click “+”, search for Flask. Then click Install Package, after the installation is complete, type PIP Freeze in Terminal, then a lot of stuff is output and for the corresponding version

  • Create a small demo

    Create an app.py file under the project and enter the program

    # coding:utf8
    from flask import Flask
    
    app = Flask(__name__)
    
    @app.route("/")
    def index():
        return "<h1 style='color:red'>Hello world</h1>"
    
    if __name__ == "__main__":
        app.run()
    Copy the code

    Right click, Run and it will display

Finally, type this address into your browser and the result is as follows