Building Web Applications in Django Coursera Quiz Answers

Coursera was launched in 2012 by Daphne Koller and Andrew Ng with the goal of giving life-changing learning experiences to students all around the world. In the modern day, Coursera is a worldwide online learning platform that provides anybody, anywhere with access to online courses and degrees from top institutions and corporations.

Join Now

Week 01: Building Web Applications in Django Coursera Quiz Answers

Quiz 1: Django Tutorial Part 2

Q1. These questions come from the Django project tutorial materials.

What is the default database backend for Django projects when they are first set up?

  • sqlite3
  • MongoDB
  • Oracle
  • PostgreSQL
  • MySQL

Q2. What file contains the list of INSTALLED_APPS in a Django project?

  • views.py
  • settings.py
  • manage.py
  • urls.py
  • apps.py

Q3. What does the “python manage.py migrate” command do?

  • Makes a backup copy of db.sqlite3
  • Moves the application to a new server
  • Builds/updates the database structure for the project
  • Moves login sessions to the backing store

Q4. What is the purpose of the models.py file?

  • To connect your database to the Django administration interface
  • To apply a regular expression to the incoming path in the request object
  • To make building views for your application simpler
  • To define the shape of the data objects to be stored in a database

Q5. What does the “sqlmigrate” option accomplish in a Django application?

  • It copies all of your SQL into a REST-based API
  • It builds/updates the database structure for the project
  • It moves all of your non-SQL data into flat files
  • It lets you see the SQL that will run to effect a migration

Q6. What does the str method in a Django model accomplish?

  • It determines how the model will respond to stress
  • It lets you specify how an instance of the model will be represented as a string
  • It improves the strength of the binding between SQL and the model
  • It indicates how strict the storage model will be in terms of column length

Q7. What is the difference between the Django shell and a normal interactive Python shell?

  • The Django shell loads all of the project objects before starting
  • The Django shell uses JavaScript instead of Python
  • You can run Django commands in a Python shell
  • Only the Python shell can print values

Q8. What is the Django command to create a user/password for the admin user interface?

  • createsuperuser
  • MOVE CORRESPONDING INTO USER
  • INSERT INTO User;
  • //SYSIN DD USER

Q9. What file in a Django application do you edit to make sure a model appears in the admin interface?

  • admin.py
  • module.py
  • sakaiger.py
  • views.py

Quiz 2: Model View Controller

Q1. Which of these might you find in the View of a Django MVC application?

  • HTML
  • SQL
  • Python
  • PHP

Q2. Which of these might you find in the Model of a Django MVC application?

  • HTML
  • SQL
  • Python
  • PHP

Q3. Which of these might you find in the Controller of a Django MVC application?

  • HTML
  • SQL;
  • Python
  • PHP

Q4. Which of the following is typically the first task when handing an incoming HTTP request in web server code?

  • Handle check the input data
  • Store the input data
  • Retrieve any needed data for the View
  • Produce and return the HTTP Response

Q5. Which of the following files does Django consult first when it receives an incoming HTTP Request?

  • urls.py
  • views.py
  • models.py
  • forms.py
  • templates/polls/main.html

Q6. Which of the following files in a Django application most closely captures the notion of “View”?

  • urls.py
  • views.py
  • models.py
  • forms.py
  • templates/polls/main.html

Q7. Which file represents the “Controller” aspect of a Django application?

  • forms.py
  • More than one file
  • models.py
  • views.py;

Week 2: Building Web Applications in Django Coursera Quiz Answers

Quiz 1: Templates and Views

Q1. What does the built-in Django template tag “lorem” do?

  • Displays random “lorem ipsum” Latin text
  • Displays the number of remaining learning objects
  • Returns true if there are learning objects on the page
  • Displays the overall number of learning objects

Q2. What does the built-in Django template tag “spaceless” do?

  • Removes whitespace between HTML tags
  • Shows data with a dark blue background and white text
  • Uses a smaller font so text fits into the available space
  • Returns true if the text will fit in a smaller space

Q3. What does the built-in Django template tag “url” do?

  • Encodes the provided string using the URL encoding rules
  • Returns an absolute path reference matching a given view and optional parameters
  • Emits an anchor (a) tag in the HTML
  • Checks if the provided string is a valid URL

Q4. What built-in Django template filter capitalizes the first character of the value?

  • ucfirst
  • capfirst
  • toupper
  • toUCFirst;

Q5. What does the built-in Django template filter “length” do?

  • Returns the number of characters produced by the template up to this point
  • Returns the length of a string but not the length of a list
  • Returns the number of words in a string
  • Returns the length of a list or string
  • Returns the length of a list but not the length of a string

Q6. What does the built-in Django template filter “safe” do?

  • Marks a string as requiring HTML escaping prior to output
  • Marks a string as not requiring further HTML escaping prior to output
  • Exits the template processing and ignores the rest of the template
  • Locks the next HTML tag so it cannot be modified in a browser debugger

Q7. Looking at the Django built-in template and filter documentation, the author seems to have a pet named “Joel”. What kind of animal is their pet?

  • A dog
  • A slug
  • A bearded gecko
  • A cat

Q8. What does the Django built-in template tag forloop.counter represent in a Django template?

  • The current iteration of the loop (1-indexed)
  • The current iteration of the loop (0-indexed)
  • The number of iterations from the end of the loop (1-indexed)
  • The number of iterations from the end of the loop (0-indexed);

Quiz 2: Tutorial 3

Q1. These questions come from the Django project tutorial materials.

When you see a path with the following pattern in urls.py, path(‘/’, views.detail, name=’detail’),

where in the code does the question_id value parsed from the URL end up?

  • As an additional parameter to the detail() view
  • As a global variable in views.py
  • In the context that is passed to the render engine
  • As part of the database connection used by the model
  • In the cookies structure

Q2. What kind of data is passed into a view in the ‘request’ object?

  • Information about the incoming HTTP request from the browser
  • A list of all the models available to the application
  • All the possible combinations of context variables
  • All of the global Python variables

Q3. Which of the following SQL commands will be run by the Question.objects.values() statement in a view function?

  • SELECT
  • INSERT
  • UPDATE
  • DELETE

Q4. How do you indicate that a particular question cannot be found in a detail view?

  • Raise an Http404 exception
  • Send back an HttpResponse with the text ‘not found’
  • Send back a blank page
  • Raise an Http500 exception;

Q5. How do you retrieve only the first five objects in a table using a Django model query?

  • Add [:5] to the end of the model query
  • Add a LIMIT clause to the retrieved SQL
  • Retrieve all the records and then write a loop to discard all but the first 5
  • Use an SQL DELETE to remove all the records beyond the first 5

Q6. In Django, why do we add an extra folder (i.e., namespace) our templates?

  • To make sure there is not a conflict with a template of the same name in a different application
  • To make it harder to find and edit template files
  • To make sure that no other application can use a template file
  • To make it impossible to extend a template from one application in another application

Q7. What is the difference between a list view and detail view?

  • A list view shows multiple items and a detail view shows only one item
  • A list view lists all the fields in a model item and the detail view focuses on one field
  • A list view throws a 404 error but a detail view never throws a 404 error

Q8. What is a “404” error?;

  • It tells a browser that it did not get the page it was looking for
  • It tells the browser that it needs to redirect to another url
  • It tells the browser that it lacks the necessary authorization to view the requested page
  • It tells the browser that something unexpected and bad happened inside the server as it was fulfilling the request

Q9. In Django, what is the default language used in HMTL template files?

DTL – Django Templating language

  • Handlebars
  • Moustache
  • HAML
  • VTL – Velocity Templating Language
  • JSP – Java Server Pages

Q10. If the “get_object_or_404()” helper function finds the requested item, it returns the item. What happens if it cannot return the item?

  • It raises an Http404 exception
  • It returns -1
  • It returns False
  • It returns an empty object

Q11. Why do we name space URL names using the “app_name” variable in the urls.py file?

  • In case we have multiple applications with the same named path
  • To make it harder to write the urls.py file
  • To make sure that no other application can access our local paths
  • To make it impossible reference a path from one application in another application

Week 3: Building Web Applications in Django Coursera Quiz Answers

Quiz 1: Object Oriented Python

Q1. Which came first, the instance or the class?

  • class
  • instance

Q2. In Object Oriented Programming, what is another name for the attributes of an object?

  • portions
  • messages
  • forms
  • methods
  • fields

Q3. Which of the following is NOT a good synonym for “class” in Python?

  • template
  • pattern
  • blueprint
  • direction

Q4. What does this Python statement do if PartyAnimal is a class?

zap = PartyAnimal()

  • Subtract the value of the zap variable from the value in the PartyAnimal variable and put the difference in zap
  • Use the PartyAnimal template to make a new object and assign it to zap
  • Copy the value from the PartyAnimal variable to the variable zap
  • Clear out all the data in the PartyAnimal variable and put the old values for the data in zap;

Q5. What is the syntax to look up the fullname attribute in an object stored in the variable colleen?

  • $colleen[“fullname”]
  • $colleen->fullname
  • $colleen->$fullname
  • $colleen::fullname
  • colleen.fullname

Q6. Which of the following statements are used to indicate that class A will inherit all the features of class B?

  • class A inherits B:
  • class A instanceOf B;
  • class A(B):
  • class A extends B:

Q7. What is “self” typically used for in a Python method within a class?

  • To refer to the instance in which the method is being called
  • To terminate a loop
  • To retrieve the number of parameters to the method
  • To set the residual value in an expression where the method is used

Q8. What does the Python dir() function show when we pass an object into it as a parameter?

  • It shows the type of the object
  • It shows the parent class
  • It shows the number of parameters to the constructor
  • It shows the methods and attributes of an object

Q9. Which of the following is rarely used in Object Oriented Programming?

  • Inheritance
  • Method
  • Destructor
  • Constructor
  • Attribute;

Quiz 2: Generic Views

Q1. In the class django.views.generic.list.ListView, which of the following methods is called earliest in the process?

  • get_template_names()
  • get_queryset()
  • get_context_data()
  • render_to_response()

Q2. In the class django.views.generic.list.ListView, which of the following methods is called latest in the process?

  • get_template_names()
  • get_queryset()
  • get_context_data()
  • render_to_response()

Q3. 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()

Q4. In the class django.views.generic.detail.DetailView, which of the following methods is called latest in the process?

  • dispatch()
  • get_queryset()
  • get_object()
  • render_to_response();

Q5. 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.html
  • templates/abc/dog_detail.djtl
  • templates/dog_detail.djtl
  • templates/doc/abc_detail.djtl

Q6. 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_name
  • template
  • template_override
  • template_extend

Q7. 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?

  • dog_list;
  • dogs
  • dogs_select
  • dogs.values()

Q8. For the following line in a views.py file

class ArticleListView(ListView):

what is the best description of “ListView”?

  • The class that is being extended
  • The class that is being created
  • The name of a view function
  • The first parameter to the render() method

Q9. For the following line in a views.py file

class ArticleListView(ListView):

what is the best description of “ArticleListView”?

  • The class that is being extended
  • The class that is being created
  • The name of a view function
  • The first parameter to the render() method

Q10. 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 the Django source
  • In views.py
  • In settings.py
  • In urls.py

Week 4: Building Web Applications in Django Coursera Quiz Answers

Quiz 1: Tutorial 4

Q1. These questions come from the Django project tutorial materials.

What is stored in the variable request.POST?

  • The next page to redirect the browser to after the processing is complete
  • A dictionary-like object that lets you access submitted POST data
  • The code that runs after a view method is complete
  • The name of the model to store an extra copy of the incoming data

Q2. What does the django.urls.reverse() function do?

  • It reverses the order of the characters in a string
  • It sends the POST data back to the browser if there is an error
  • It sends a 404 error if the record cannot be loaded
  • It constructs the path to a view using the name of a path entry in urls.py

Q3. What happens if you access a detail view like results() in Django tutorial 4 and provide a key that does not exist on the URL?

  • The server crashes and sends you a 500
  • You get a 404
  • You get a 200
  • The record is automatically created but left empty

Q4. In the polls/templates/polls/detail.html file in Django tutorial 4, what happens if you leave out the csrf_token line in the form?

  • The POST data will be blocked by the server
  • The form will look strange in the user’s browser
  • 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

Q5. In the 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?

  • choice.choice_text
  • forloop.counter
  • url ‘polls:vote’ question.id
  • question.question_text

Q6. Which HTTP method is used when sending data to the server that will modify or update data?

  • 404
  • GET
  • POST
  • 200

Q7. What does the Django template filter “pluralize” do?

  • It converts a word to the plural form depending on the user’s selected language
  • It emits an ‘s’ if the value is > 1
  • It splits a string using a specific delimiter character
  • It returns a random item from the given list;

Quiz 2: Forms and HTML

Q1. Which of the following HTTP methods adds form data to the URL after a question mark?

  • GET
  • POST
  • 200
  • 404

Q2. Which of the following HTTP methods is recommended for sending data to the server that will modify a model?

  • GET
  • POST
  • 200
  • 404

Q3. Which of the following Python types is most like the request.POST data in Django?

  • dictionary
  • list
  • string
  • tuple

Q4. 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
  • At the end of the Content-Type request header
  • Appended to the URL after a question mark;

Q5. When using the password field type in HTML, the data is encrypted before it is sent to the server.

  • True
  • False

Q6. There is no way the end user can see the actual data stored in a password form field.

  • True
  • False

Q7. How do radio buttons in HTML associate with each other?

  • They use the same name parameter
  • They come right after one another in the HTML
  • They are part of a radio-group tag
  • They must be in the same paragraph (p tag)

Q8. What HTTP response code is sent to a browser when a missing or incorrect CSRF value is detected by Django?

  • 403
  • 302
  • 500
  • 200

Q9. What HTTP code is sent to the browser to redirect it to another page?

  • 302
  • 200
  • 403
  • 500

Q10. Why do we consider the POST-Redirect-GET pattern best practice?

  • To avoid triggering the browser double-POST popup
  • To handle files as attachments
  • To make sure that cookies are not stolen
  • To validate incoming data in a form

.

Review:

Based on our knowledge, we urge you to enroll in this course so you can pick up new skills from specialists. It will be worthwhile, we trust.

 

Leave a Comment