Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions as per they have mentioned in their official website. Moreover I personally find this as best framework to start with as it provides quick implementations. A beginner can easily setup a project and gradually scale the project with Flask.
Working with framework can be little bit challenging at beginning, but use of framework always saves your time. Do in competitive world of today, try to learn and make best use of it.
Installing Python
To verify if python is installed on your Windows System
C:\> py -V # will show version of python installed on your windows system
To verify if python is installed on your Ubuntu(Linux) & Apple Mac System
$ python -V # will show version of python installed on your ubuntu
OR
$ python3 -V # will show version of python installed on your ubuntu
If you don't have python installed please visit http://python.org and in download section under Files choose the type of installation you want I would suggest Windows executable installer. I would recommend to install and use python3 if you have python 2.
Verifying & Installing pip
for Windows
To check if pip(python package manager) is installed. Either of one code should be successfully exected in system which show version of pip
C:\> pip -V
or
C:\> py -m pip -V
If you don't have pip follow the instruction provided in below to install pip
https://pip.pypa.io/en/stable/installing/#do-i-need-to-install-pip
Again, run code given above to veify if pip is installed.
for Ubuntu
You will require python so make sure you have python installed on your system. One you have python setup you need to install pip (which is python package manager).
$ sudo apt-get install python-pip # for python2 $ sudo apt-get install python3-pip # for python3
for Mac
pip should be availabe by default, just to verify you can check by
$ pip -V # for python2
$ pip3 -V # for python3
Installing Flask
After you have pip in place you can install Flask (for both Linux and Mac)
$ pip install Flask # for python2 $ pip3 install Flask # for python3
If you are in windows and above code didn't work try code given below
C:\> py -m pip install Flask
Writing simple Flask Application
Now create new file as app.py in your any project folder and put down following code and save the file.
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
Running our Flask Application
Flask comes with developemnt server. Enter the code given below and in your address bar of browser type http://localhost:5000
$ python app.py
or
$ python3 app.py
If you are in Windows then
C:\> py app.py
This was simple demonstration of flask application setup. Please visit http://flask.pocoo.org/ for more.
Comments