NEW
Font size
WorksheetsDjango Features and Libraries (Курс 3)
Total questions: 63
Worksheet time: 32mins
What part of a Django application handles session management?
Middleware
Templates
Views
Models
Where are cookies stored?
In the browser
On the server
In the database
Locally on the disk
Which protocol determines how cookies are sent back and forth?
HTTP
SMTP
FTP
SSH
Which of the following Python structures is most like cookie storage?
dictionary
set
list
tuple
Any server can read any cookie from any other server.
False
True
What kind of cookies are deleted when the browser is closed?
Session cookies
Persistent cookies
Secure cookies
Third-party cookies
What is the method you call in a Django view to set a cookie?
response.set_cookie()
request.set_cookie()
cookie.set()
save_cookie()
How many times do you need to set a cookie for it to persist across a number of incoming requests?
Once
Each time a request is made
Monthly
Annually
What is the typical approach to making a session identifier?
Choose a large random number
Sequential numbering
User's email address
Current timestamp
Where is session data typically stored in a Django application?
In the server
In the client's computer
In the cookie directly
In a third-party service
How do you set a key of 'abc' to the value 'test' in the session in a Django application?
request.session['abc'] = 'test';
request.set('abc', 'test');
session['abc'] = 'test';
request.session.set('abc', 'test');
Which came first?
Cookie
Session
Both at the same time
Neither exists
Which came second?
Session
Cookie
Both at the same time
Neither exists
Which best describes the Django functionality that puts up the login form?
Application
Middleware
Template
Model
Which best describes the Django functionality that supports sessions?
Middleware
Application
Template
Model
What happens when the user passes a login check?
Information is added to the session
The session is deleted
The user is redirected to a static page
A new user profile is created automatically
What string is returned by django.urls.reverse('login') in dj4e-samples?
/accounts/login
/login
/user/login
/auth/login
What is the purpose of the next parameter on a login or logout URL?
It tells the authentication system where to go after the action is complete
It encrypts the following page
It logs out the user immediately
It determines the authentication method
What is the value in a Django template to print out the current logged-in user's email address?
In a Django template, what is stored in the request.path variable?
The URL of the currently executing request
The physical server path
The user's IP address
The template's file path
What is the default name of the template that Django will load when presenting the user with a login screen?
registration/login.html
user/login.html
accounts/login.html
login/form.html
What variable do you check in a Django view to see if this request is from a logged-in user?
What Django class does a class-based view need to extend to indicate that the view can only be accessed by logged-in users?
LoginRequiredMixin
SecureAccessMixin
UserRequiredMixin
AuthRequiredMixin
Which of the following is NOT a benefit of using the Django forms capability?
Database portability
Enhanced security
Built-in validation
Automatic HTML generation
What happens when a Create form is submitted and Django forms detects a validation error?
The form is re-displayed with the incorrect data and error messages
The form is saved with default values
The form submission is ignored
The server automatically corrects the errors
You cannot use a Django form unless it is connected to a Django Model.
False
True
How do you indicate that you want to display a form using the Crispy library in a template?
form|crispy
form.crispy()
crispy(form)
display(form|crispy)
What does the fields="all" statement do in the Meta section of a Django form class?
Indicates that all of the underlying model fields should be in the form
Excludes all fields from the form
Includes only the primary key field in the form
Randomly selects fields for the form
In what method in a view class would you expect to see "form.save()" to save data from an incoming form?
post()
get()
delete()
put()
What utility method simplifies the code needed to load the old model data when processing an update request?
get_object_or_404()
update_object_or_404()
load_object_or_fail()
find_object()
What is the primary value add of relational databases over flat files?
Ability to scan large amounts of data quickly
Easier to duplicate data
No need for structured query language
Data can only be accessed by one user at a time
Use a person's email address as their primary key
False
True
Make a table that maps the strings in the column to numbers and then use those numbers in the column
True
False
Which of the following is the label we give a column that the "outside world" uses to look up a particular row?
Logical key
Foreign key
Internal key
Hidden key
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?
Foreign key
External key
Pointer key
Reference key
What is a simple rule that captures much of the concepts of "database normalization"?
Don't replicate string data in a column
Always use numeric identifiers
Store all data in a single table
Use text fields for all data types
What is the SQL keyword that reconnects rows containing foreign keys with the corresponding data in the table that the foreign keys point to?
JOIN
MERGE
LINK
BIND
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"?
xyz_id
abc_xyz
fk_xyz
abc_to_xyz
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"?
id
xyz_id
primary_key
xyz_primary
Which of the following model field types is used for a foreign key?
ForeignKey
PrimaryKeyField
ReferenceField
LinkField
What does an "on_delete=models.CASCADE" clause imply in a Model field in Django?
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.
The child rows are archived
The deletion is reversed
The child rows become new parent rows
When you add an index to a field in a database table, how are performance and storage affected?
Read performance is faster, insert performance is slower, and extra storage is required
Insert performance improves, no storage impact
No change in performance or storage
Reduces storage but increases read time
Why do we insist on producing a delete confirmation screen?
Because a GET request should never modify data
To provide a better user interface
For compliance with security standards
To increase server processing time
Which of the following methods is called first in the Django generic list view?
setup()
get()
dispatch()
render()
Which method do we override in the Django generic list view to keep users from making changes to rows they don't own?
get_queryset()
get_context_data()
get_form()
validate_user()
What does OwnerUpdateView do if a user tries to delete a record that does not belong to them?
It returns a 404 (not found error)
It redirects to the homepage
It logs out the user
It sends a warning email
What template variable indicates the current logged-in user?
user
profile
current_user
session_user
What is the name of the model that Django uses to store User objects?
settings.AUTH_USER_MODEL
User
UserProfile
AuthUser
What is the database relationship between the Article model and User model?
One-to-Many
One-to-One
Many-to-Many
None
In views.py in the myarts sample code, what is the purpose of the "fields" class-wide value?
To limit the model fields displayed in the form
To specify which fields are mandatory
To define field validation rules
To encrypt certain fields
For a data model named Frog, what is the generic Edit View convention for the template used when editing a Frog object?
frog_form.html
frog_edit.html
edit_frog.html
frog_template.html
In the OwnerCreateView class, what method is overridden to set the "owner" field to the current logged-in user?
form_valid()
form_save()
save_form()
validate_form()
In OwnerUpdateView, how do we make sure that the current logged-in user cannot retrieve any rows that don't belong to them?
We add a model filter
We check user permissions
We use a session validator
We implement a user query limit
In OwnerUpdateView, which is the "super" or "parent" class?
UpdateView
DetailView
ListView
FormView
When a generic edit view is receiving POST data, which of the following steps is done first?
clean()
save()
validate()
preprocess()
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?
3
2
4
1
If you were looking at a link in a data model diagram, which of these would represent a many-to-many relationship?
0..* --- 1..*
1..1 --- 1..1
1 --- 1
0..1 --- 1..1
In Django, what type of field is used to represent a many-to-many relationship?
models.ManyToManyField
models.OneToOneField
models.ForeignKey
models.LinkField
Which of the following is NOT a common name for the additional table needed to represent a many-to-many relationship between two tables?
Lookup table
Join table
Bridge table
Link table
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?
through
via
using
connect
What kind of model fields will be found in every Junction table?
models.ForeignKey
models.CharField
models.IntegerField
models.DateField
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?
insert the book, insert the connection, insert the author
insert the author, insert the book, insert the connection
insert the connection, insert the book, insert the author
insert the connection, insert the author, insert the book
You should never have any fields other than keys in a Junction table.
False
True
