Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the introduction and installation of Flask

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about the introduction and installation of Flask, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

I believe that most people come in to read this article because they have not been exposed to the Flask framework before. Here I would like to introduce this framework to you.

Introduction to Flask

Flask is a Web development micro-framework implemented in Python. Its main purpose is to develop Web applications, Web should be known to everyone, that is, web pages. So when we finish learning Flask, we can write a small website by ourselves.

Flask is a lightweight framework, it is not as heavyweight as Django (Baidu Django), but both lightweight and heavyweight have their own advantages and disadvantages. The Flask we are about to learn has the advantages of freedom, flexibility and high customization.

Flask, which was born in 2010, is a lightweight Web development framework written by Armin ronacher based on the Werkzeug toolkit in Python. It is mainly for small applications with simple requirements.

Flask itself is equivalent to a kernel, almost all other functions need to be extended (mail extension Flask-Mail, user authentication Flask-Login), and need to be implemented by third-party extensions. For example, email extension Flask-Mail, user authentication Flask-Login, database Flask-SQLAlchemy and so on.

There is no default database for Flask. You can choose either MySQL or NoSQL. Its WSGI toolbox uses Werkzeug (routing module), and the template engine uses Jinja2.

Flask relies on two external libraries: the Jinja2 template engine and the Werkzeug WSGI toolset. These two are the core of the Flask framework.

The most famous framework of Python is Django, as well as Flask, Tornado and other frameworks. Although Flask is not the most famous framework, Flask should be one of the most flexible frameworks, which is why Flask is popular with developers.

After reading the history, let's talk about Flask itself. The Flask framework provides a lot of extension packages for us developers, such as:

Flask-SQLalchemy: manipulating databases

Flask-migrate: managing the migration database

Flask-Mail: Mail

Flask-WTF: form

Flask-script: inserting script

Flask-Login: authenticate user statu

Flask-RESTful: a tool for developing REST API

Flask-Bootstrap: integrated front-end Twitter Bootstrap framework

Flask-Moment: localization date and time

These expansion packages greatly facilitate our development.

I would also like to talk about my own opinions on Flask. I highly recommend that you learn this framework because each of us not only have to master those heavyweight development frameworks (Django), but also have to learn some lightweight frameworks, which is helpful for us to use something quickly when we suddenly need something urgently.

The official documentation of Flask is also available here:

Chinese document: http://docs.jinkan.org/docs/flask/

English document: https://flask.palletsprojects.com/

Interested friends can refer to it!

Pre-installation of Flask

When using the Flask framework, you are generally developing a Web project.

As mentioned above, Flask relies mainly on two libraries. Jinja2 and Werkzeug.

Werkzeug is a toolset of WSGI (marking python interfaces between Web applications and multiple servers)

Jinja2 is responsible for rendering the template. So you need to install these two external libraries before installing flask.

The easiest way is to install a virtual environment before installing Flask to isolate Flask projects from other environments.

Install a virtual environment

1. Install Virtualenv

The installation method is simple, and you can install it using the following cmd.

Pip install virtualenv

two。 After the installation is complete, use the following cmd to detect the Virtualenv version

Virtualenv-version

If it is shown in the figure above, the installation is successful!

Create a virtual environment

The virtual environment is generally named venv, so use the following cmd to create the virtual environment.

Virtualenv venv

After the run is complete, a folder of venv appears under the run directory, which is a brand new virtual environment. There is a private python interpreter.

Activate the virtual environment

To activate the current virtual environment before using the virtual environment, you can activate it using the following cmd.

Venv\ Scripts\ activate

The activation was successful as shown in the figure above.

Installation of Flask

Pip is installed automatically when the virtual environment is created, so install flask using the following cmd.

Pip install flask

After the installation is successful, you can view all installation packages using the following cmd

Pip list-format columns

When flask is successfully installed as shown in the figure, both Jinja2 and Werkzeug, the dependent libraries of flask, are successfully installed at the same time!

So far, all the work of Flask is ready.

The above is the introduction and installation of Flask, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report