What is Flask?
Flask is a micro-framework of python which is used in web development and has an easy to use syntax and makes use of jinja2 as the templating engine.
Flask makes backend web development a piece of cake for new learners because of the following reasons:-
· Most Universities teach python so we don’t need to learn a new language
· It takes minimal time to learn for a person having basic knowledge of python
· Compatible with SQL and NoSQL databases
Let’s get into the installation steps and learn some basic syntax
Pre-requisites:-Python must be installed in your computer
If python is installed we can install flask using pip which is python’s package manager
Just open the terminal and type the following command
pip install -U Flask
Once flask is installed you are ready to get started
How to learn Flask?
There are numerous web sources through which flask could be learnt . If one has previous backend knowledge the Flask Documentation is the best place to learn it
Otherwise one can refer the following course on YouTube:-
· Python Flask by Traversy media
· Flask Tutorials by Corey Schafer
These two are one of the best free sources to learn Flask and get yourself underway in backend web development
Why Flask May Be Better Than Django
If your motive is to learn a backend framework quickly flask is the way to go.It helps us to get a feel of what backend programming is like.If the main focus of the programmer is experience flask is the better option.
However if you are more focused upon your end product and have enough backend experience Django might be better for you as it will help to reduce your efforts.
In short Flask is more simple and flexible but Django provides a better control to the programmer
from flask import Flask #The first line basically imports flaskapp = Flask(__name__) # __name__ is set to the current class function, method ,descriptor, or generator firstname.lastname@example.org('/') # a basic route, it will print hello word when run on localhost:portnumber/def hello():return 'Hello, World!'
Note:- Explanation for each line is in the comments above
On running the Server through Command line we will see:-
$ FLASK_APP=hello.py flask run* Serving Flask app "hello"* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Here are a few links one may refer to get going in Flask
Flask documentation:- http://flask.pocoo.org/docs/1.0
Flask Tutorials by Corey Schafer . :- https://www.youtube.com/watch?v=MwZwr5Tvyxo&list=PL-osiE80TeTs4UjLw5MM6OjgkjFeUxCYH
Flask Tutorials by Traversy media:- https://www.youtube.com/watch?v=zRwy8gtgJ1A