Building Web Applications in Django | Week 2

Course Name: Django for Everybody

Sub-course: Building Web Applications in Django

Course Link: Django for Everybody

Sub-course Link: Building Web Applications in Django

These are Building Web Applications in Django Week 2 answers Coursera Quiz


Templates and Views

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

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

Answer: Displays random “lorem ipsum” Latin text


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

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

Answer: Removes whitespace between HTML tags


These are Building Web Applications in Django Week 2 Answers Coursera Quiz


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

  • Checks if the provided string is a valid URL
  • 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

Answer: Returns an absolute path reference matching a given view and optional parameters


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

  • toUCFirst
  • capfirst
  • toupper
  • ucfirst

Answer: capfirst


These are Building Web Applications in Django Week 2 Answers Coursera Quiz


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 list but not the length of a string
  • 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

Answer: Returns the length of a list or 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

Answer: Marks a string as not requiring further HTML escaping prior to output


These are Building Web Applications in Django Week 2 Answers Coursera Quiz


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 cat
  • A dog
  • A slug
  • A bearded gecko

Answer: A slug


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 number of iterations from the end of the loop (0-indexed)
  • The current iteration of the loop (0-indexed)
  • The number of iterations from the end of the loop (1-indexed)

Answer: The current iteration of the loop (1-indexed)


These are Building Web Applications in Django Week 2 Answers Coursera Quiz


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

Answer: As an additional parameter to the detail() view


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

Answer: Information about the incoming HTTP request from the browser


These are Building Web Applications in Django Week 2 Answers Coursera Quiz


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

  • SELECT
  • INSERT
  • UPDATE
  • DELETE

Answer: SELECT


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

Answer: Raise an Http404 exception


These are Building Web Applications in Django Week 2 Answers Coursera Quiz


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

  • 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

Answer: Add [:5] to the end of the model query


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

Answer: To make sure there is not a conflict with a template of the same name in a different application


These are Building Web Applications in Django Week 2 Answers Coursera Quiz


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

Answer: A list view shows multiple items and a detail view shows only one item


These are Building Web Applications in Django Week 2 Answers Coursera Quiz


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

Answer: It tells a browser that it did not get the page it was looking for


These are Building Web Applications in Django Week 2 Answers Coursera Quiz


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

Answer: DTL – Django Templating language


These are Building Web Applications in Django Week 2 Answers Coursera Quiz


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

Answer: It raises an Http404 exception


These are Building Web Applications in Django Week 2 Answers Coursera Quiz


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

Answer: In case we have multiple applications with the same named path


These are Building Web Applications in Django Week 2 Answers Coursera Quiz


More Weeks of this course: Click Here

More Coursera Courses: http://progiez.com/coursera


These are Building Web Applications in Django Week 2 Answers Coursera Quiz
The content uploaded on this website is for reference purposes only. Please do it yourself first.