skFla Flashcards

1
Q

What is the default host port and port of Flask?

A

localhost (127.0.0.1), and the default port is 5000

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to change default host and port in Flask?

A

app.run(host=”0.0.0.0”, port=8080)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what are some Flask commands?

A

sdfsfdsf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

request object in Flask

A
@app.route("/")
def index():
    val = request.args.get("var")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to get the user agent in Flask

A
@app.route("/")
def index():
    user_agent = request.headers.get('User-Agent')
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to use url_for in the Flask application?

A

Flask’s url_for function helps in creating dynamic routes. We can make use of url_for in the Flask templates.

<a>{{post.title}}</a><a></a>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

View function for handling variables in routes

A
@app.route(“/blog/post/”)
def get_post_id(post_id):
return post_id
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to create an Admin interface in Flask?

A

We can create an Admin interface in Flask using the Flask-Admin extension, or the Flask-Appbuilder extension

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the Flask-Admin extension help with?

A

grouping views together into classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Does Flask-Appbuilder already come with an Admin interface?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why is Flask called a Microframework?

A

Flask only provides core features such as request, routing, and blueprints. For other features, such as Caching, ORM, forms, etc., we need to make use of Flask-Extensions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How can we integrate the Twitter API?

A

To integrate with Flask, we can make use of a Flask extension called Flask-Social. It not only helps in authenticating users from Twitter but also other social platforms or accounts such as Facebook and Google. We need to use Flask-Social along with Flask-Security.

We need to install individual API libraries in Python and also need to get consumer and secret keys by registering the Flask application on the external account providers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are some benefits of using the Flask framework?

A
It has an inbuilt development server.
    It has vast third-party extensions.
    It has a tiny API and can be quickly learned by a web developer.
    It is WSGI compliant.
    It supports Unicode.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Is the SQLite database built-in Flask?

A

SQLite is in-built with Python. Inside the view, we can import SQLite and write SQL queries for interacting with the database

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What do most Flask devs usually use for SQLite?

A

Flask-SQLAlchemy, which eliminates the need to write complex SQL queries and is an ORM to interact with the SQLite database

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a template engine in Flask?

A

A template is a file that contains two types of data, i.e., static and dynamic. Dynamic data in a template is populated during run time

17
Q

What does Flask make use of to let devs create HTML templates?

A

Jinja2

18
Q

What method allows placeholders in templates to be filled with dynamic data?

A

render_template()

19
Q

What do you mean by Thread local object in Flask?

A

In Flask, thread-safety has been provided out of the box. We can use objects such as current_app, g, and request without worrying about problems related to locking and concurrency. Moreover, we need not pass objects from methods to methods, and these objects are generally available within a valid request context.

This attribute of Flask makes it a bit unique and provides a lot of convenience to the Flask developers while keeping Flask application thread-safe

20
Q

What is the difference between Django and Flask? Why should one choose Flask?

A

Django is also a web development framework created in the Python programming language. It is a full-featured web application framework with a lot of features that are built into it, such as an Admin backend, and an ORM with migration capability. It is a little bit older and more mature.

Flask is better for quick development use cases and is perfect for prototyping. Django has inspired even some Flask extensions that are written. Flask is more suitable for developing lightweight web applications that do not require a large codebase. It is apt for developing microservices or serverless applications.

Flask is easy to learn and has fewer API’s when compared to Django. As the industry is following the trends towards microservices served as part of containers, it is excellent to keep Flask in your web development toolkit.

21
Q

Describe the features of Forms extension for Flask

A

Forms in Flask can be implemented by using an extension called Flask-WTF. Flask-WTF is created by integrating Flask with WTForms. WTForms is a python-based form rendering and validation library. It supports data validation, internationalization, and CSRF protection.

Flask-WTF also provides reCAPTCHA support along with file uploads when tied with Flask-Uploads. You also can handle JavaScript requests, and customize the error response

22
Q

https://www.softwaretestinghelp.com/flask-interview-questions-with-answers/

A

question 25

23
Q

https://www.softwaretestinghelp.com/python-flask-tutorial/

A

list of flask tuts