Q1). What is Flask?
Ans1: Flask is a web micro framework for Python based on “Werkzeug, Jinja 2 and good intentions” BSD licensed. Werkzeug and jingja are two of its dependencies.
Q2). What is the benefit of using Flask?
Ans2: 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.
Q3). What is the difference between Django, Pyramid, and Flask?
Ans3: 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.
Q4). What is Flask-WTF and what are their features?
Ans4: Flask-WTF offers simple integration with WTForms. Features include for Flask WTF are
- Integration with wtforms
- Secure form with csrf token
- Global csrf protection
- Internationalization integration
- Recaptcha supporting
- File upload that works with Flask Uploads
Q5). What is the common way for the Flask script to work?
Ans5: The common way for the flask script to work is
- Either it should be the import path for your application
- Or the path to a Python file
Q6). Explain how you can access sessions in Flask?
Ans6: 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.
Q7). Is Flask an MVC model and if yes give an example showing MVC pattern for your application?
Ans7: Basically, Flask is a minimalistic framework which behaves same as MVC framework. So MVC is a perfect fit for Flask, and the pattern for MVC we will consider for the following example
from flask import Flask
app = Flask(_name_)
@app.route(“/”)
Def hello():
return “Hello World”
app.run(debug = True)
In this code your,
- Configuration part will be
from flask import Flask
app = Flask(_name_)
- View part will be
@app.route(“/”)
Def hello():
return “Hello World”
- While you model or main part will be
app.run(debug = True)