What is Flask?
Flask is a web application framework written in Python language, which is developed by Armin Ronacher. It is based on werkzeug WSGI(Web server gateway Interface) toolkit and Jinja2 template engine. Flask provides you tools, libraries and technologies that allow you to build a web application.
WSGI or Web server gateway interface has been adopted as a standard for Python web application development. It is a specification for UI(Universal Interface) between web servers and web applications.
A WSGI (Web server gateway interface) is a toolkit that is used to implement requests, response objects and other utility functions. The most important feature of using it is to enable building a web framework. The Flask framework uses Werkzeug as one of its bases.
Jinja2 is a popular template engine for python. A web template system combines a template with a certain data source to render dynamic web pages.
Flask is also termed as micro-framework. Its aim is to keep the core of an application simple yet extensible. It doesn’t have any built-in abstraction layer for database handling, nor it has form validation support.
Flask- Environment Setup
Firstly, you have to create a virtual environment that will be used as a container to hold all the packages in it. So, we have to set up an environment for this. We have a prerequisite to use python 2.7 or above version. But python 2.7 is soon going to we deprecated so we recommend you to use python 3.3 or above version to take advantage of the Flask framework in your web server or web application.
The first step is to set up the virtual environment and in that we have to first install the virtualenv to create an environment with ease. To install that go to the terminal or command prompt as per your operating system and run the given command:
pip install virtualenv
Note: Before running this command make sure you have an active internet connection on your system.
If this command shows the error related to the permission then try running the command (for mac/ubuntu user) as,
sudo pip install virtualenv
and run the command prompt as administrator and run the same command without sudo if you are a windows user.
Creating a project and virtual environment:
Now, I can assume that the virtualenv is successfully installed on your system. So, it’s time to start and new project and to create a virtual environment for it.
Firstly, in the terminal create a new directory to store all the needed files in it and move to thids directory using the given command,
$ mkdir my_project $ cd my_project
Secondly, you have to create a virtual environment with repect to the python version that you want to use in your project using the given command,
$ virtualenv -p python3.6 venv
So, this command will create a virtual environment with name venv and python version 3.6 on the current directory.
After that you have to activate virtual environment that you have just created with the command given below according to your operating system,
$ source venv/bin/activate
This will activate the virtual environment that you have just created. You can now install the packages you want to install, and those packages will be installed in your virtual environment. This clearly means that to use those packages further in your script, you have to activate the virtual environment before it’s execution.
Lastly, you have to install the flask package on your virtual environment by following the given command to install it and this command is valid in all operating system,
(venv)$ pip install flask
This will install flask in your virtual environment.
Furthermore, we will be using python programming to work with the flask web framework, so it is important for you to have a basic understanding of the python programming language.
If you are new to programming language the I would recommend you to learn python first to understand the flask clearly for that here is the reference for you to learn python and not to waste time searching for it on google. Check this out and improve your programming skills.
Also, you can check here if you want to build your own first chatbot.
Feel free to leave your doubts in the comment section.