This is an article about the development of Flask , about Flask is what, how to build Flask Development environment and other content.
What is Flask?
Flask is a lightweight web Services frameworkdeveloped by the Python language ,Flask by Armin Ronacher made an April Fool's joke and developed so far.
What is the Flask in my Heart
Flask 's fast, lightweight scalability has the advantage of being able to think about what I want to develop, and I don't have to think about it too much. Just think of what I might want to do now, so Flask can do it. Flask has too many expansion packs, you just need to know how to use these extensions to do many of your unexpected features.
Flask is a quick Web framework written based on Python , and there's a question,Flask and How much does Python really relate to? This is a very in-depth question, and my understanding is that Flask is python,python , non- Flask , and I'm not going to explain why. Because this is everyone's opinion, I do not want to see every friend of the article because read my article on the thinking of a lock, I found too many articles in the reader in the process of reading to lock the mind, which greatly affect the reader's thinking.
Of course, I'm not saying that Flask not be allowed to build large projects, and the preparation of large projects requires more, not within the scope of this article. If you have time later , you can talk about how to think about building large projects .
Now, consider your understanding of Flask .
Build Flask Development Environment
Whether you are using Linux,Mac,Windows build environment is very easy, read the official documents can do the environment deployment here I explain again.
Installing virtualenv
Linux and Mac:
sudo pip install virtualenv
Windows:
You first need to assign the Script directory under the Python root directory to the system PATH and execute it. Most importantly, you'll need to install gitunder Windows and use git bash instead of the original CMD .
Easy_install Pip # install pip
Pip Install Virtualenv
Create a project folder
Mac,Linux
Mkdir-p ~/DOCUMENT/FLASK-BB & CD ~/DOCUMENT/FLASK-BB # Create a folder and move to a folder
Virtualenv venv # Create virtualenv Standalone Environment
Windows
Create a folder named Flask-bbin the drive you want, and do not take Chinese in the path.
Right-click inside the project folder to choose Git Bash here
Virtualenv venv # Create virtualenv Standalone Environment
Using virtualenv
Mac,Linux input in project directory
. Venv/bin/activate # Notice there's one in front . and Spaces
The terminal enters the virtualenv Environment and joins at the front of the prompt (venv)
under Windows system, also open Git Bash within the project folder
. Venv/script/activate # Note . and Spaces
Now that we have successfully deployed and used the virtualenv Environment, What is the use of virtualenv? It is actually a handy Python virtual Environment, because Flask features, each project will have different expansion packages to expand the project itself. For the sake of cleanliness, do not install every expansion pack used in the root Python environment. So we have a small virtual Python environment where the Flask extension Package for the current project can be applied for installation.
Tip:virtualenv is not just for Flask, it can be any Python development environment as long as you need it. You can set different virtualenv environments for your different projects .
You need a database
In this article, I chose to use Mysql as a database, although SQLite is simpler, you can create files at will, there are problems directly deleted. But MySQL is used both locally and on the server for the sake of our local development and the actual deployment in production to keep the database consistent, and the MySQL -based GUI There are many management software, you can search yourself to install in your own system environment . Mysql .
This time I used the Mysql 5.6 version and created a database encoding format of utf8mb4 default collation for Utf8mb4_bin database tables. It is recommended that you create a new account to manage this database table.
Run Flask
After deploying the Flask Environment, how do we need to use it?
First we need to install Flask. After entering the virtualenv Environment, run the following command:
Pip Install flask # Install flask
Pip Install Flask-script # installs flask-script to replace native boot management
Pip Install Flask-sqlalchemy # install flask-sqlalchemy to manage the database
Pip Install Mysql-python # install mysql-python Drive Database
The next thing to note is that the code for the full functionality of the Flaskblog We now need can be written in a . py file, But I really don't recommend it (and I'm sure no one would recommend it). If this is very inconvenient to extend the functional surface, the functionality described in this article is limited to very basic content, but want to extend is very easy, and the entire project file and folder planning, it is more convenient for us to expand the efficiency of development later!
The following article all files, I will label the file path based on the root directory.
For example:
The/config.py is on the project directory root.
/app/main.py creates a folder under the project directory to create an app main.py
Start writing it!
Article from: Programming School
Flask Development Basics Tutorial