Flask Interview Questions

Facebooktwitterredditpinterestlinkedinmailby feather

1) What is Flask?

Flask is a micro web framework written in Python. It is based on Werkzeug toolkit and Jinja 2 template engine.

2) Who is the developer of Flask?

Armin Ronacher is the developer of Flask.

3) What is the stable version of Flask?

The stable version of Flask is 0.12.2 and released on 16 May 2017.

4) What are Flask-WTF and its features?

It is a template form that is integrated with Flask. It includes various features that are given below.

  • It provides integration with WTF
  • It manages secure form with CSRF token
  • It manages global CSRF protection
  • It provides Internationalization integration
  • It supports recaptcha
  • It handles the file upload that works with Flask uploads

5) What is the benefit of flask?

Flask is a part of the micro-framework. It does not require external libraries. It makes the framework light weight, less dependent and less security bugs.

6) What are the differences between Django, Pyramid and Flask?

There are following differences between Django, pyramid and Flask:

Django Pyramid Flask
It is a python framework. It is same as Django. It is micro framework.
It is used to build large applications. It is same as Django . It is used to create small application.
It includes an ORM. It provides flexibility and right tools. It does not require external libraries.

7) What is the appropriate way to work with Flask script?

The appropriate way to work with flask script includes the following steps:

  • Either it should be the import path for our application
  • Or the path to a Python file

8) How can we access sessions in Flask?

In Flask, a session allow 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.

9) How can we request database connections in Flask?

Flask provides three ways to establish database connection. These are given below.

  1. before_request() : It is called before a request and requires no arguments.
  2. after_request() : It is called after a request and pass the response that will be sent to the client
  3. 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.

10) What is Flask Sijax?

Flask Sijax is a Simple Ajax & jQuery library. It is used to enable Ajax in web applications. It uses JSON to pass data between the server and the browser.

11) How can we get a query string from the Flask?

We can get a query string from the flask by using following function.

  1. @app.route(‘/data’)
  2.     def data ( ) :
  3.     user = request.arg.get (‘user’)

12) How can we create request context in Flask?

We can create request context by using following ways.

  • Automatically when the application receives a request
  • OR manually, by calling app.test_request_context (‘/route?param=value)

13) How can we create structure of large Flask application?

We can create structure of large Flask application by using following steps:

  • attach to the functions and move them to different files.
  • Use blueprints to assign the views to “categories”. For instance auth, profile, backend, etc.
  • Use the underlying Werkzeug URL map and register functions on there on a central URL.

14) What are the attributes of request objects?

There are various attributes of request objects:

Attributes Description
Form It is a dictionary object containing key.
Args It parsed contents of query string which is part of URL after question mark (?).
Cookies Dictionary object holds Cookie names and values.
Files Data pertaining to uploaded file.
Method Current request method.

15) What are the Mail class methods?

There are following Mail class method:

  • send(): It is used to send contents of Message class object.
  • connect(): It is used to opens connection with mail host.
  • send_message(): It is used to sends message object.

16) What are the steps to develop MVC web application in Flask?

There are following steps to develop web application:

    • Flask import Flask
    • Configuration part will be
    • View part will be

 

    • While you model or main part will be

17) What is the extension of Flask?

The extension of Flask is .Py.

18) What is the default port of Flask?

The default port of Flask is 5000.

19) What is url_for() function in Flask?

In Flask, url_for() function is used to build dynamic URL for specific function.

20) What are the HTTP methods in Flask?

In Flask, the HTTP methods are given below:

  • GET : It is used to send the data in unencrypted form to the server.
  • HEAD : It is same as GET, but without response body.
  • POST: It is used to send HTML from data to server. Data received by POST method.
  • PUT : It is used to replaces all the current representation uploaded content
  • DELETE : It is used to removes all current reorientation.

21) What is the default route request in Flask?

In Flask, GET is the default route request.

22) 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

23) What is the use redirect() function.

Redirect() function is used to display the login page again when a login attempt fails.

24) What are the error codes in Flask?

In Flask, the error code is given below:

  • 400 âˆ’ for Bad Request.
  • 401 âˆ’ for Unauthenticated.
  • 403 âˆ’ for Forbidden.
  • 404 âˆ’ for Not Found.
  • 406 âˆ’ for Not Acceptable.
  • 415 âˆ’ for Unsupported Media Type.
  • 429 âˆ’ Too Many Requests.

25) How can we create a form for file uploading?

We can create a form for file uploading by using following code:

26) What are the Mail methods in Flask?

In Flask, the Mail methods are given below:

  • send(): It is used to send contents of message class object.
  • connect(): It is used to open connection with mail host.
  • send_message(): It is used to send message object.

27) What are the validators class of WTForms in Flask?

In Flask, The validators class of WTForm are listed in below table:

Validators class Description
DataRequired It is used to check whether input field is empty
Email It is used to check whether text in the field follows email ID conventions.
IPAddress It is used to validate IP address in input field
Length It is used to verify if length of string in input field is in given range
NumberRange It is used to validates a number in input field within given range
URL It is used to validates URL entered in input field

28) Does Flask support in-built SQlite database?

Yes, Flask supports in-built SQlite database.

29) What is ORM?

ORM stands for Object Relation Mapping. It is a technique of mapping object parameter.

30) What is WSGI?

WSGI stands for Web Server Gateway Interface. It is used to python web application development.

31) What are the popular server that contains WSGI application and Server HTTP?

There are many popular server that contains WSGI application and server HTTP:

  • Gunicorn
  • Tornado
  • Gevent
  • Twisted Web
Facebooktwitterredditpinterestlinkedinmailby feather

Leave a Comment