Google News
logo
Flask Interview Questions
Flask is an API of Python that allows us to build up web-applications. It was developed by Armin Ronacher. Flask’s framework is more explicit than Django’s framework and is also easier to learn because it has less base code to implement a simple web-Application. A Web-Application Framework or Web Framework is the collection of modules and libraries that helps the developer to write applications without writing the low-level codes such as protocols, thread management, etc. Flask is based on WSGI(Web Server Gateway Interface) toolkit and Jinja2 template engine.
Flask Python is one of the newest frameworks of Python and is used for designing web applications for the following features :
 
* Flask comes with built-in development server as well as fast debugger
* It is based on Unicode.
* Python Flask is extensively documented.
* It also contains the integrated support required for unit testing
* It has the feature of restful request dispatching
* Comes with Jinja2 templating technique
* Flask supports secure cookies i.e. client-side sessions
* Also has the WSGI 1.0 compliant feature.
Flask Python comes with all the advantages of Python and some additional pros of it are :
 
* Flasks design is lightweight and modular. Therefore, it is easy to transform it into the web applications or framework when one needs very few extensions without weighing much.
* Flask is ORM-agnostic : i.e. user can plug in their favorite ORM like SqlAlchemy
* The basic foundation of API is very nicely shaped and made coherent.
* Documentation of flask is very comprehensive, filled with lots of examples and are well structured. Users can even try out some sample applications to really get the real feel of Flask.
* It is very easy to deploy Flask in production as Flask comes with 100% WSGI 1.0 compliant
* Flask can handle HTTP request easily with help of its functionalities
* It is highly flexible. Its configuration is even more flexible than that of Django, which gives its users plenty of solutions for every product they need.
Flask is part of the micro-framework. Which means it will have little to no dependencies on external libraries. It makes the framework light while there is little dependency to update and less security bugs.
The development version of the Flask framework can be obtained using the below-mentioned commands.
 
cd flask && python3 setup.py develop
Flask is a “microframework” primarily build for a small application with simpler requirements. In flask, you have to use external libraries. Flask is ready to use.
 
Pyramid are build for larger applications. It provides flexibility and lets the developer use the right tools for their project. The developer can choose the database, URL structure, templating style and more. Pyramid is heavy configurable.
 
Like Pyramid, Django can also used for larger applications. It includes an ORM.
A session basically allows you to remember information from one request to another. In a flask, it uses a signed cookie so the user can look at the session contents and modify. The user can modify the session if only it has the secret key Flask.secret_key.
Flask-WTF is featured to offer simple integration with WTForms. The Features include for Flask WTF are :
 
* Provides Integration with web forms
* Is very secure form as it comes with CSRF token
* Provides global CSRF protection
* Comes with internationalization integration
* Also features Recaptcha supporting
* Contains File upload that closely works with Flask Uploads
Flask default host and port can be changed by passing the values to host and port parameters while calling run method on the app.
 
from flask import Flask
app = Flask(__name__)
 
@app.route("/")
def index():
    return "Hello, World!"
 
if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8080)

 

HTTP methods are used to retrieve data from an URL :
 
GET : The GET is the method that sends data to the server unencrypted.
HEAD :  HEAD is similar to GET, but that it has no response body.
POST : The POST server does not cache the HTML form data that it sends
PUT : It is the method in which the uploaded content replaces current data representations of the target resources.
DELETE : This method removes the current representations of the target resource that is suggested by a URL.