Flask was created by Armin Ronacher of Pocoo which is an international group of Python enthusiasts formed in 2004. Flask is a lightweight Python web framework based on Werkzeug and Jinja 2, Flask tackles Routing, HTML template rendering, Sessions etc. If you are building web applications on Linux, then I highly recommend using Flask.
Flask is an extremely functional and powerful framework that is most popular and very much extensible with a great choice of third party libraries.
Flask is called a micro framework because it does not presume or force a developer to use a particular tool or library. It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions. However, Flask supports extensions that can add application features as if they were implemented in Flask itself.
The Gunicorn also known as "Green Unicorn" is a Python Web Server Gateway Interface (WSGI) HTTP server. It is a pre-fork worker model, ported from Ruby's Unicorn project.
The Gunicorn server is broadly compatible with a number of web frameworks, simply implemented, light on server resources and fairly fast.
Flask was designed to be easy to use and extend. Flask is great for all kinds of projects. It's especially good for prototyping. Flask depends on two external libraries: the Jinja2 template engine and the Werkzeug WSGI toolkit.
Despite the lack of a major release, Flask has become extremely popular among Python enthusiasts. Flask provides several very useful features, some of them are listed below.
Flask has a lightweight and modular design, so it easy to transform it to the web framework you need with a few extensions without weighing it down
HTTP request handling functionality and High Flexibility
Support for secure cookies (client side sessions) and Integrated support for unit testing
Built-in development server and fast debugger
Flask documentation are comprehensive, full of examples and well structured. You can even try out some sample application to really get a feel of Flask.
Jinja2 templating and WSGI 1.0 compliant
In this tutorial, we will learn how to set up the Gunicorn application server to launch the application and Nginx to act as a front end reverse proxy.
A server running Ubuntu-14.04.
A static IP Address for your server.
A non-root user account with sudo privilege set up on your server.
Nginx is a free, open-source, high-performance HTTP server and reverse proxy server, also known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.
It has reached its popularity due to being light weight, relatively easy to work with and easy to extend with add-ons and plug-ins.
Before starting, update the system by running the following commands:
sudo apt-get updatesudo apt-get upgrade
Then, install Nginx by running the following command:
sudo apt-get install nginx
Next, start Nginx service by running the following command:
sudo /etc/init.d/nginx start
Then, add Nginx service to start at boot time by running the following command:
You can test Nginx configuration by running the following command:
sudo nginx -t
You will see the following output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Now, start Nginx service by running the following command:
sudo /etc/init.d/nginx start
Congrats!.. You should now able to see your application by running the following curl command:
You should see the following output:
This is sample Flask App
In this tutorial, you have learned to create a Flask application within a Python virtual environment, create WSGI entry point, configure the Gunicorn app server to provide this function and created an Nginx server block that passes web client traffic to the application server.
You can also design your own app and serve the flask applications.
Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will...
Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you...