Get in touch
or send us a question?

Developing Python Web with Flask – Section 1

Install and create HelloWorld sample
1. Environment
.OS: Centos 7.x
.Framework: Flask
.Python 2.7
[root@localhost ~]# python -V
Python 2.7.5

1.1 Install Python
CentOS 7 is still defaulting to Python 2.7

1.2 Install pip
yum install epel-release
yum -y install python-devel
yum -y install python-pip
pip install pip –upgrade

Check pip version
[root@localhost src]# pip -V
pip 9.0.3 from /usr/lib/python2.7/site-packages (python 2.7)

1.3 Install virtualenv for development environment
virtualenv is a virtual Python environment builder. It helps a user to create multiple Python environments side-by-side. Thereby, it can avoid compatibility issues between the different versions of the libraries.

pip install virtualenv

1.4 Install Flask framework
pip install Flask

Install Flask

2. Create a new project
mkdir HelloWorl
cd HelloWorl
virtualenv venv

Create a new project

Activate environment
[root@localhost HelloWorl]# chmod -Rf 755 venv/
[root@localhost HelloWorl]# venv/bin/activate

Activate environment

4. Create Hello World
4.1 Edit a file

from flask import Flask
app = Flask(__name__)

def hello_world():
return ‘Hello World!’

if __name__ == ‘__main__’:’′, port=5000, debug=True)

4.2 Runing test

A message in Python shell informs you that
* Running on (Press CTRL+C to quit)

Open the above URL (localhost:5000) in the browser. ‘Hello World!’ message will be displayed on it.

BrowserWould you like to work with us in NeosCorp, please contact us here!

Notify of
Inline Feedbacks
View all comments