Exam part 2

Ace your homework & exams now with Quizwiz!

What string is returned by "x = django.urls.reverse('login')" in dj4e-samples? /dj4e-samples/login /login /accounts/login nigol

/accounts/login

Which best describes the Django functionality that puts up the login form? Model Application TemplateTag Middleware

application

How to you indicate that you want to display a form using the Crispy library in a template? csrf_token form|crispy form.as_crispy form.as_table

form|crispy

In polls/templates/polls/detail.html file in Django tutorial 4, which bit of code tells the view that will receive the POST data which question to associate this vote with. question.question_text url 'polls:vote' question.id forloop.counter choice.choice_text

url 'polls:vote' question.id

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

user.email

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"? id abc_xyz_id abc_id xyz_id

xyz_id

Which HTTP code is sent to the browser to redirect it to another page? 403 200 302 500

302

What HTTP response code is sent to a browser when a missing or incorrect CSRF value is detected by Django? 302 500 200 403

403

These questions come from the Django project tutorial materials. What is stored in the variable request.POST? A dictionary-like object that lets you access submitted POST data The name of the model to store an extra copy of the incoming data The code that runs after a view method is complete The next page to redirect the browser to after the processing is complete

A dictionary-like object that lets you access submitted POST data

What is the primary value add of relational databases over flat files? Ability to quickly convert data to HTML Ability to store data in a format that can be sent across a network Ability to execute JavaScript in the file Ability to scan large amounts of data quickly Ability to execute Python code within the file

Ability to scan large amounts of data quickly

What is the typical approach to making a session identifier? Use the logged in user's email address Compute an MD5 hash of the user's email address Choose a large random number Start at 1 and add 1 for each new session (like a primary key)

Chose a large random number

Which came first? Cookie, Session, Login

Cookie

Which of the following is *not* a benefit of using the Django forms capability? You can have a mapping layer between your models and templates You reduce the amount of HTML you need to generate You can add complex form validation rules to your application Database portability You can easily create attractively styled forms

Database portability

Which of the following Python classes is most like cookie storage? Dictionary Set List Database connection Template

Dictionary

Which of the following Python types it most like the request.POST data in Django? list tuple string dictionary

Dictionary

What is a simple rule that captures much of the concepts of "database normalization"? Every SELECT statement must use a JOIN clause Do not point to a primary key more than once Don't use any non-standard SQL statements Don't replicate string data in a column

Don't replicate string data in a column

T/F: Any server can read any cookie from any other server

False

T/F: There is no way the end use can see the actual data stored in a password form field

False

T/F: When using the password field type in HTML, the data is encypted before it is sent to the server

False

What is the label we give to a column that is an integer and used to point to a row in a different table? Primary key Local key Logical key Foreign key Remote key

Foreign key

Which of the folowing model field types is used for a foreign key? OneToManyKey ForeignKey OneToManyField RemoteKey

ForeignKey

Which of the following HTTP methods add form data to the URL after a question mark? GET 404 200 POST

GET

Which protocol determines how cookies are sent back and forth? CSS SQL ORM HTTP HTML

HTTP

Where are cookies stored? In the database In the Python code In elasticache In the browser

In the browser

Where is session data typically stored in a Django application? In the browser In the server In JavaScript variables On the end-user's hard drive

In the server

What does the fields="__all__" statement do in the Meta section of a Django form class? Indicates that the owner field is not supposed to be shown to the user when the form is displayed Indicates that all of the underlying model fields should be in the form Indicates that none of the model fields are to be saved

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

What happens when the user passes a login check? A new record is asses to the auth_group table A cookie is set A new record is added to the auth_user table Information is added to the session

Information is added to the session

These questions come from the Django project tutorial materials What does the django.urls.reverse() function do? It reverses the order of the characters in a string It sends a 404 error if the record cannot be loaded It sends the POST data back to the browser in the case there is an error It constructs the path to a view using the name of a path entry in urls.py

It constructs the path to a view using the name of a path entry in urls.py

What does the Django template filter "pluralize" do? It splits a string using a specifice delimiter character It returns a random item from the given list It emits an 's' if the value is > 1 It converts a word to the plural form depending on the user's selected language

It emits an 's' if the value is > 1

What is the purpose of the *next* parameter on a login or logout URL? It moves to the next item in a linked list It tells the authentication system where to go after the action is complete It indicates which record to start with in a list that exceeds the length of the page It advances the iteration variable in a for loop

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

What is the SQL keyword that reconnects rows with foreign keys with the corresponding data in the table that the foreign key points to? CONNECT COUNT APPEND CONSTRAINT JOIN

JOIN

Which of the following is the label we give a column that the "outside world" uses to look up a particular row? Remote key Local key Primary key Foreign key Logical key

Logical key

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

LoginRequiredMixin

What part of a Django application handles session management? Middleware Views Templates Models

Middleware

Which best describes the Django functionality that supports sessions? Model Middleware TemplateTag Application

Middleware

Which HTTP method is used when sending data to the server what will modify or update data? 200 GET 404 POST

POST

Which of the following HTTP methods is recommended for sending data to the server that will modify a model? 200 POST GET 404

POST

When you add an index to a field in a database table, how are performance and storage affected? Read performance is the faster, insert performance is faster and extra storage is required Read performance is faster, insert performance is the same and no extra storage is required Read performance is the same, insert performance is faster and no extra storage is required Read performance is faster, insert performance is slower and extra storage is required

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

Which came second? Cookie, Session, Login

Session

What kind of cookies are deleted when the browser is closed? Inverse cookies Bitcoin cookies Encrypted cookies Session cookies

Session cookies

For the following line in a urls.py file urlpatterns = [ path('', TemplateView.as_view(template_name='gview/main.html')), ..." Where would you find the actual code for TemplateView? In urls.py In views.py Somewhere in the Django source In settings.py

Somewhere in the Django source

In a Django template, what is stored in the request.path variable? It indicates the actual table name of the model that is currently in use A string indicating the path to the 'parent' folder A list of breadcrumbs of recently visited URLs The URL of the currently executing request

The URL of the currently executing request

For the following line in a views.py file ""class ArticleListView(ListView):"" what is the best description of ""ArticleListView""? The first parameter to the render() method The name of a view function The class that is being extended The class that is being created

The class that is being created

For the following line in a views.py file ""class ArticleListView(ListView):"" what is the best description of ""ListView""? The name of a view function The class that is being created The first parameter to the render() method The class that is being extended

The class that is being extended"

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 re-displayed with the error messages A 403 (Not authorized) is send back to the browser The form is re-displayed with the incorrect data The record is deleted form the database

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

In polls/templates/polls/detail.html file in Django tutorial 4, what happens if you leave out the csrf_token line in the form? The server will not know which object to retrieve once the POST data is sent The favicon will not show up properly in the title bar The post data will be blocked by the server The form will look strange in the user's browser

The post data will be blocked by the server

How do radio buttons in HTML associate with each other? The use the same name parameter They are part of a radio-group tag The must be in the same paragraph (p tag) They come right after one another in the HTML

The use the same name parameter

What is the reason that we consider the POST-Redirect-GET pattern best practice? To avoid triggering the browser double-POST popup To make sure that cookies are not stolen To handle files as attachments To validate incoming data in a form

To avoid triggering the browser double-POST popup

Which of the following is NOT a good rule to follow when developing a database model? Use a persons email address as their primary key Each "object" in the application should be modeled as one or more tables Use integers as primary keys Never repeat string data in more than one table in a data model

Use a persons email address as their primary key

How does the browser send form data to the server when sending a POST request? Using the socket after the request headers have been sent Using a second socket connection Appended to the URL after a question mark At the end of the Content-Type request header

Using the socket after the request headers have been sent

If our user interface (i.e. like iTunes) has repeated strings on one column of the UI, how should we model this properly in a database: We make a table that maps the strings in the column to numbers and then use those numbers in the column We put the string in the last row where it occurs and put the number of that row in the column all of the rest of the rows where the string occurs We put the string in the first row it occurs and then put that row number in the column all of the rest of the rows where the string occurs We put the string in the first row where it occurs and then NULL in all of the other rows Encode the entire row as JSON and store it in a TEXT column in the database

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

What does an "on_delete=models.CASCADE 11 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 When rows in a child table are deleted, the primary key of the corresponding row in the parent table is set to NULL Whenever a row is deleted, it is moved into a table named "CASCADE" Whenever a row is deleted from the table, the other rows are scanned to insure that the logical key is unique and any duplicates are removed

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

What happens if you access a detail view like results0 in Django tutorial 4 and provide a key that does not exist on the URL? You get a 404 The server crashes and sends you a 500 You get a 200 The record is automatically created but left empty

You get a 404

In the class django.views.generic.detail.DetailView, which of the following methods is called earliest in the process? dispatch() get_queryset() get_object() render_to_response()

dispatch()

By convention when using an app_name of "abc" and a model of "Dog", if you use a View that extends django.views.generic.list.ListView, what is the name of the context variable that will include all the Dog objects in the template when it is being rendered? dogs.values() dogs dogs_select dog_list

dog_list

What utility method simplifies the code needed to load the old model data when processing an update request? get_object_or_404() contitional_render_404() render_to_template_with_check() load_try_except()

get_object_or_404()

In the class django.views.generic.list.ListView, which of the following methods is called earliest in the process? get_template_names() render_to_response() get_queryset() get_context_data()

get_template_names()

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"? xyz_id id abc_xyz_id abc_id

id

How many times do you need to set a cookie for it to persist across a number of incoming requests? On every response to a POST request On every request On every non-anonymous request Once

once

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

post ()

What is the default name of the emplate that Django will load when presenting the user with a login screen? auth/auth.html home/login.html registration/login.html autos/login.html

registration/login.html

In the class django.views.generic.detail.DetailView, which of the following methods is called latest in the process? get_object() dispatch() render_to_response() get_queryset()

render_to_response()

In the class django.views.generic.list.ListView, which of the following methods is called latest in the process? get_template_names() render_to_response() get_context_data() get_queryset()

render_to_response()

How do you set a key of 'abc' to the value 'test' in the session in a Django application? request.session['abc'] = 'test' request.session.get('abc', 'test') response.session['abc'] = 'test' $_SESSION['abc'] = 'test'; request.session['abc', 'test']

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

What variable do you check in a Django view to see if this request is from a logged in user? request.authenticated request.user.auth is_authenticated.view request.user.is_authenticated

request.user.is_authenticated

What is the method you call in a Django view to set a cookie? response.cookie.set() $_COOKIES[] = 'value' response.set_cookie() request.setCookie()

response.set_cookie()

If you want to override the template name chosen by convention in a View that extends django.views.generic.detail.DetailView what is the name of the class attribute variable that you use? template_extend template_override template_name template

template_name

By convention when using an app_name of "abc" and a model of "Dog", if you use a View that extends django.views.generic.detail.DetailView, what is the file name that will be used for the template? templates/abc/dog_detail.djtl templates/abc/dog_detail.html templates/dog_detail.djtl templates/doc/abc_detail.djtl

templates/abc/dog_detail.html


Related study sets

WEEK 5 :: PYTHON CRASH COURSE :: OBJECT ORIENTED PROGRAMMING

View Set

Chapter 2 - Using Financial Statements and Budgets

View Set

Ch. 19: Environmental Law & Policy

View Set

Introduction to Management: Week 3, planning

View Set

chapter 1: introduction to demography

View Set

Cardio Practice questions, Neuro NCLEX, NCLEX Neuro disorders, Lewis Chapter 48, Endocrine, Liver Failure, Hepatitis, cholecystitis, pancreatitis, NCLEX, Urinary NCLEX Questions, Med-surg Test #3, Urinary NCLEX QUESTIONS, Fluids and Electrolytes_Test...

View Set