wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Django Features and Libraries (Курс 3)

Total questions: 63

Worksheet time: 32mins

Name
Class
Date
1.

What part of a Django application handles session management?

a)

Middleware

b)

Templates

c)

Views

d)

Models

2.

Where are cookies stored?

a)

In the browser

b)

On the server

c)

In the database

d)

Locally on the disk

3.

Which protocol determines how cookies are sent back and forth?

a)

HTTP

b)

SMTP

c)

FTP

d)

SSH

4.

Which of the following Python structures is most like cookie storage?

a)

dictionary

b)

set

c)

list

d)

tuple

5.

Any server can read any cookie from any other server.

a)

False

b)

True

6.

What kind of cookies are deleted when the browser is closed?

a)

Session cookies

b)

Persistent cookies

c)

Secure cookies

d)

Third-party cookies

7.

What is the method you call in a Django view to set a cookie?

a)

response.set_cookie()

b)

request.set_cookie()

c)

cookie.set()

d)

save_cookie()

8.

How many times do you need to set a cookie for it to persist across a number of incoming requests?

a)

Once

b)

Each time a request is made

c)

Monthly

d)

Annually

9.

What is the typical approach to making a session identifier?

a)

Choose a large random number

b)

Sequential numbering

c)

User's email address

d)

Current timestamp

10.

Where is session data typically stored in a Django application?

a)

In the server

b)

In the client's computer

c)

In the cookie directly

d)

In a third-party service

11.

How do you set a key of 'abc' to the value 'test' in the session in a Django application?

a)

request.session['abc'] = 'test';

b)

request.set('abc', 'test');

c)

session['abc'] = 'test';

d)

request.session.set('abc', 'test');

12.

Which came first?

a)

Cookie

b)

Session

c)

Both at the same time

d)

Neither exists

13.

Which came second?

a)

Session

b)

Cookie

c)

Both at the same time

d)

Neither exists

14.

Which best describes the Django functionality that puts up the login form?

a)

Application

b)

Middleware

c)

Template

d)

Model

15.

Which best describes the Django functionality that supports sessions?

a)

Middleware

b)

Application

c)

Template

d)

Model

16.

What happens when the user passes a login check?

a)

Information is added to the session

b)

The session is deleted

c)

The user is redirected to a static page

d)

A new user profile is created automatically

17.

What string is returned by django.urls.reverse('login') in dj4e-samples?

a)

/accounts/login

b)

/login

c)

/user/login

d)

/auth/login

18.

What is the purpose of the next parameter on a login or logout URL?

a)

It tells the authentication system where to go after the action is complete

b)

It encrypts the following page

c)

It logs out the user immediately

d)

It determines the authentication method

19.

What is the value in a Django template to print out the current logged-in user's email address?

b)

user.mail

d)

account.user_email

20.

In a Django template, what is stored in the request.path variable?

a)

The URL of the currently executing request

b)

The physical server path

c)

The user's IP address

d)

The template's file path

21.

What is the default name of the template that Django will load when presenting the user with a login screen?

a)

registration/login.html

b)

user/login.html

c)

accounts/login.html

d)

login/form.html

22.

What variable do you check in a Django view to see if this request is from a logged-in user?

a)

request.user.is_authenticated

b)

request.is_user_logged_in

c)

user.is_active

d)

session.isAuthenticated

23.

What Django class does a class-based view need to extend to indicate that the view can only be accessed by logged-in users?

a)

LoginRequiredMixin

b)

SecureAccessMixin

c)

UserRequiredMixin

d)

AuthRequiredMixin

24.

Which of the following is NOT a benefit of using the Django forms capability?

a)

Database portability

b)

Enhanced security

c)

Built-in validation

d)

Automatic HTML generation

25.

What happens when a Create form is submitted and Django forms detects a validation error?

a)

The form is re-displayed with the incorrect data and error messages

b)

The form is saved with default values

c)

The form submission is ignored

d)

The server automatically corrects the errors

26.

You cannot use a Django form unless it is connected to a Django Model.

a)

False

b)

True

27.

How do you indicate that you want to display a form using the Crispy library in a template?

a)

form|crispy

b)

form.crispy()

c)

crispy(form)

d)

display(form|crispy)

28.

What does the fields="all" statement do in the Meta section of a Django form class?

a)

Indicates that all of the underlying model fields should be in the form

b)

Excludes all fields from the form

c)

Includes only the primary key field in the form

d)

Randomly selects fields for the form

29.

In what method in a view class would you expect to see "form.save()" to save data from an incoming form?

a)

post()

b)

get()

c)

delete()

d)

put()

30.

What utility method simplifies the code needed to load the old model data when processing an update request?

a)

get_object_or_404()

b)

update_object_or_404()

c)

load_object_or_fail()

d)

find_object()

31.

What is the primary value add of relational databases over flat files?

a)

Ability to scan large amounts of data quickly

b)

Easier to duplicate data

c)

No need for structured query language

d)

Data can only be accessed by one user at a time

32.

Use a person's email address as their primary key

a)

False

b)

True

33.

Make a table that maps the strings in the column to numbers and then use those numbers in the column

a)

True

b)

False

34.

Which of the following is the label we give a column that the "outside world" uses to look up a particular row?

a)

Logical key

b)

Foreign key

c)

Internal key

d)

Hidden key

35.

What is the label we give to a column that is an integer and is used to point to a row in a different table?

a)

Foreign key

b)

External key

c)

Pointer key

d)

Reference key

36.

What is a simple rule that captures much of the concepts of "database normalization"?

a)

Don't replicate string data in a column

b)

Always use numeric identifiers

c)

Store all data in a single table

d)

Use text fields for all data types

37.

What is the SQL keyword that reconnects rows containing foreign keys with the corresponding data in the table that the foreign keys point to?

a)

JOIN

b)

MERGE

c)

LINK

d)

BIND

38.

If we are following the default convention in Django, which of the following column names would be used for a foreign key in table "abc" that is pointing to a primary key in table "xyz"?

a)

xyz_id

b)

abc_xyz

c)

fk_xyz

d)

abc_to_xyz

39.

If we are following the default convention in Django, which of the following column names would be used for a primary key in table "xyz" that is pointed to from a foreign key in table "abc"?

a)

id

b)

xyz_id

c)

primary_key

d)

xyz_primary

40.

Which of the following model field types is used for a foreign key?

a)

ForeignKey

b)

PrimaryKeyField

c)

ReferenceField

d)

LinkField

41.

What does an "on_delete=models.CASCADE" clause imply in a Model field in Django?

a)

When a row in the parent table is deleted, all the rows in a child table that point to that row via a foreign key are deleted.

b)

The child rows are archived

c)

The deletion is reversed

d)

The child rows become new parent rows

42.

When you add an index to a field in a database table, how are performance and storage affected?

a)

Read performance is faster, insert performance is slower, and extra storage is required

b)

Insert performance improves, no storage impact

c)

No change in performance or storage

d)

Reduces storage but increases read time

43.

Why do we insist on producing a delete confirmation screen?

a)

Because a GET request should never modify data

b)

To provide a better user interface

c)

For compliance with security standards

d)

To increase server processing time

44.

Which of the following methods is called first in the Django generic list view?

a)

setup()

b)

get()

c)

dispatch()

d)

render()

45.

Which method do we override in the Django generic list view to keep users from making changes to rows they don't own?

a)

get_queryset()

b)

get_context_data()

c)

get_form()

d)

validate_user()

46.

What does OwnerUpdateView do if a user tries to delete a record that does not belong to them?

a)

It returns a 404 (not found error)

b)

It redirects to the homepage

c)

It logs out the user

d)

It sends a warning email

47.

What template variable indicates the current logged-in user?

a)

user

b)

profile

c)

current_user

d)

session_user

48.

What is the name of the model that Django uses to store User objects?

a)

settings.AUTH_USER_MODEL

b)

User

c)

UserProfile

d)

AuthUser

49.

What is the database relationship between the Article model and User model?

a)

One-to-Many

b)

One-to-One

c)

Many-to-Many

d)

None

50.

In views.py in the myarts sample code, what is the purpose of the "fields" class-wide value?

a)

To limit the model fields displayed in the form

b)

To specify which fields are mandatory

c)

To define field validation rules

d)

To encrypt certain fields

51.

For a data model named Frog, what is the generic Edit View convention for the template used when editing a Frog object?

a)

frog_form.html

b)

frog_edit.html

c)

edit_frog.html

d)

frog_template.html

52.

In the OwnerCreateView class, what method is overridden to set the "owner" field to the current logged-in user?

a)

form_valid()

b)

form_save()

c)

save_form()

d)

validate_form()

53.

In OwnerUpdateView, how do we make sure that the current logged-in user cannot retrieve any rows that don't belong to them?

a)

We add a model filter

b)

We check user permissions

c)

We use a session validator

d)

We implement a user query limit

54.

In OwnerUpdateView, which is the "super" or "parent" class?

a)

UpdateView

b)

DetailView

c)

ListView

d)

FormView

55.

When a generic edit view is receiving POST data, which of the following steps is done first?

a)

clean()

b)

save()

c)

validate()

d)

preprocess()

56.

A one-to-many relationship in a data model involves two database tables. How many tables are involved in representing a many-to-many relationship?

a)

3

b)

2

c)

4

d)

1

57.

If you were looking at a link in a data model diagram, which of these would represent a many-to-many relationship?

a)

0..* --- 1..*

b)

1..1 --- 1..1

c)

1 --- 1

d)

0..1 --- 1..1

58.

In Django, what type of field is used to represent a many-to-many relationship?

a)

models.ManyToManyField

b)

models.OneToOneField

c)

models.ForeignKey

d)

models.LinkField

59.

Which of the following is NOT a common name for the additional table needed to represent a many-to-many relationship between two tables?

a)

Lookup table

b)

Join table

c)

Bridge table

d)

Link table

60.

In models.py when you want to explicitly model a Junction table, what is the attribute in the two linked table models used to indicate which Junction table to use to connect the two tables?

a)

through

b)

via

c)

using

d)

connect

61.

What kind of model fields will be found in every Junction table?

a)

models.ForeignKey

b)

models.CharField

c)

models.IntegerField

d)

models.DateField

62.

If you have a many-to-many relationship between books and authors and you are inserting a new author for a book, which of the following orders of operations will work?

a)

insert the book, insert the connection, insert the author

b)

insert the author, insert the book, insert the connection

c)

insert the connection, insert the book, insert the author

d)

insert the connection, insert the author, insert the book

63.

You should never have any fields other than keys in a Junction table.

a)

False

b)

True