What is Python Flask?
Flask is a light-weight, and Popular web application Framework. It is written in Python Programming Language. It was developed by Armin Ronacher in 2010. Flask is based on WSGI (Web Server Gateway Interface) toolkit and Jinja2 template engine. It provides you with tools, libraries and technologies that allow you to build a web application.
What is WSGI?
WSGI stands for Web server Gateway Interface. It is a specification that describes how a web server communicates with web applications, and how web applications can be chained together to process one request.
What is the use of python flask?
Python flask is used for creating API’s, blog or wiki-like platform.
What is the meaning of g in python flask?
Flask g name stands for “global” which is referring to data being global within a context. The data saved in g is lost after the context ends, and it is not an appropriate place to store data between requests.
What are the new features of Flask?
- Flask comes with built-in development server as well as fast debugger
- integrated support for unit testing
- Restful request dispatching
- Comes with Jinja2 templating technique
- It supports secure cookies i.e. client-side sessions
- Also has the WSGI 1.0 compliant feature.
- It is based on Unicode.
- Google App Engine compatibility
- Python Flask is extensively documented.
What is the use of Werkzeug in Flask?
Werkzeug is a utility library meant for usage with the Python language. Mostly, it is a Web Server Gateway Interface or WSGI app that can create software items for request, response, or utility functions.
What is use of Jinja?
Jinja is a template engine for Python programming purposes, and it resembles the Django web frameworks templates.
What is Flask-WTF and what are their features?
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
Explain, how can we access sessions in Flask?
In Flask, a session allows us to remember information from one request to another. It uses a signed cookie so the user can look at the session contents. We can access session by using the secret key Flask.secret_key in the Flask framework.
How can we request database connections in Flask?
Flask provides three ways to establish database connection. These are given below.
before_request() : It is called before a request and requires no arguments.
after_request() : It is called after a request and pass the response that will be sent to the client
teardown_request(): It is used when exception is raised and response are not guaranteed. It is called after the response and not allowed to modify the request or their values.
What is Flask Sijax?
Flask Sijax is Python/jQuery library to perform Ajax function in Flask.
You can install Flask-Sijax by using below command
easy_install flask-sijax
pip install flask-sijax
What are the HTTPs methods provided by Python Flask?
HTTPs 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 sendsPUT: 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.
What is the difference between Flask and Pyramid?
Flask can be stated as a micro framework, which is solely built for a small application, which has simpler requirements. In flask, the users have to use external libraries. Flask is always ready to use.
Pyramid is built for larger application as it provides flexibility and allows the developer use the right features for their project. The developer can choose the database, templating style URL structure and more. Pyramid is therefore heavy configurable.
What is the use redirect() function.
Redirect() function is used to display the login page again when a login attempt fails.
What are the delimiters used in Jinga2 template?
{% … %}: It is used for Statements
{{ … }}: It is used for Expressions to print to the template output
{# … #}: It is used for Comments not included in the template output
# … ## : It is used for Line Statements
What are the server 5XX errors?
- HTTP_500_INTERNAL_SERVER_ERROR
- HTTP_501_NOT_IMPLEMENTED
- HTTP_502_BAD_GATEWAY
- HTTP_503_SERVICE_UNAVAILABLE
- HTTP_504_GATEWAY_TIMEOUT
- HTTP_505_HTTP_VERSION_NOT_SUPPORTED
- HTTP_511_NETWORK_AUTHENTICATION_REQUIRED
How to get logged user id in flask?
current_user.get_id() is used to get logged in user id in flask.
Here is an example:
from flask import g
if current_user.is_authenticated():
       g.user = current_user.get_id()
How to get visitor ip address in Flask?
request.remote_addr is used to get visitor IP address in Flask. Here is an example:
from flask import request
from flask import jsonify
@app.route(“/get_user_ip”, methods=[“GET”])
def get_user_ip():
   return jsonify({‘ip’: request.remote_addr}), 200
How is memory managed in Flask Python?
Flask Python is a collection of private heap spaces, which holds all objects and data structures together. Programmers cannot access it. It is the task of the interpreter to manage it. But in the core API, users can access some of the tools. The Flask Python memory manager controls its allocation. Also, an inbuilt garbage collector is present which recycles all unused memory so it is made available for the heap space.
How can we get a query string from the Flask?
We can get a query string from the flask by using following function.
@app.route(‘/data’)
   def data ( ) :
user = request.arg.get (‘user’)
What are pickling and unpickling?
To make a portable and serialized representations of Python objects, we have the module known as pickle which accepts a Python object (basically everything in Python is an object) and then converts it into a string type, and after that uses the dump () function to dump it into a file. We term this as pickling. On the contrary, retrieving objects from the stored string forms is called as unpickling.
How one can enable debugging in Flask?
There are two ways by which users can enable debugging in Flask. They are as follows:
By setting the flag on the applications object
By passing the flag as a parameter to run. If the user is enabling to debug support, the server will reload it when the code will change and the user doesn’t have to restart after each change made in the code.
What are the validators class of WTForms in Flask?
In Flask, the validators class of WTForm are listed in below table:
DataRequired:Â To check whether input field is empty
Email: To check whether text in the field follows email ID conventions.
IPAddress: To validate IP address in input field
Length: To verify if length of string in input field is in given range
NumberRange: To validates a number in input field within given range
URL: To validates URL entered in input field
What is the default port of Flask?
What is the use of app routing in Python flask?
App routing in Flask is used to map a specific URL with the associated function that is intended to perform some task.
What are client errors in Flask?
- HTTP_400_BAD_REQUEST
- HTTP_401_UNAUTHORIZED
- HTTP_402_PAYMENT_REQUIRED
- HTTP_403_FORBIDDEN
- HTTP_404_NOT_FOUND
- HTTP_405_METHOD_NOT_ALLOWED
- HTTP_406_NOT_ACCEPTABLE
- HTTP_407_PROXY_AUTHENTICATION_REQUIRED
- HTTP_408_REQUEST_TIMEOUT
- HTTP_409_CONFLICT
- HTTP_410_GONE
- HTTP_411_LENGTH_REQUIRED
- HTTP_412_PRECONDITION_FAILED
- HTTP_413_REQUEST_ENTITY_TOO_LARGE
- HTTP_414_REQUEST_URI_TOO_LONG
- HTTP_415_UNSUPPORTED_MEDIA_TYPE
- HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE
- HTTP_417_EXPECTATION_FAILED
- HTTP_428_PRECONDITION_REQUIRED
- HTTP_429_TOO_MANY_REQUESTS
- HTTP_431_REQUEST_HEADER_FIELDS_TOO_LARGE