ExamHoot

Scenario: Prasath's Student Grade Report Template

{% for student in students %}
    <tr>
        <td>{{ forloop.counter }}</td>
        <td>{{ student.name }}</td>
        <td>{{ student.marks }}</td>
        {% if student.marks >= 80 %}
            <td>A</td>
        {% elif student.marks >= 60 %}
            <td>B</td>
        {% else %}
            <td>C</td>
        {% endif %}
    </tr>
{% empty %}
    <tr><td colspan="4">No students enrolled.</td></tr>
{% endfor %}
  1. If the students list is empty, the table will still render with zero rows.

  2. A student with 75 marks will be assigned grade 'B' because it falls in the 60-79 range.

  3. The `forloop.counter` will display the student's ID instead of their position in the list.

  4. A student with exactly 80 marks will be assigned grade 'B' because the condition uses >= operator.

Show answer & explanation

Correct answer

A student with 75 marks will be assigned grade 'B' because it falls in the 60-79 range.

Explanation

Prasath is creating a student grade report where each row displays the student's sequential number (using forloop.counter), name, marks, and a calculated grade based on mark ranges. The empty block handles the case when no students exist.

Written by ExamHoot EditorialPublished · Updated

All 29 Django Templates and Template Tags questions

  1. 1.What is the primary purpose of Django Templates?
  2. 2.Which template tag is used to iterate over a list in Django templates?
  3. 3.What is the correct syntax to display a variable in a Django template?
  4. 4.Which template tag is used to include conditional logic in Django templates?
  5. 5.What does the Django template filter 'upper' do?
  6. 6.How do you apply a filter to a variable in a Django template?
  7. 7.What is the purpose of the {% extends %} template tag?
  8. 8.Which template tag is used to define a block that can be overridden in child templates?
  9. 9.What does the 'length' filter return in Django templates?
  10. 10.How do you access dictionary values in a Django template?
  11. 11.Understanding Django Template Inheritance and Block Tags
  12. 12.Django Custom Template Filters - Implementation and Usage
  13. 13.Django Template Tag for Conditional Rendering - if/elif/else
  14. 14.Scenario:
  15. 15.Django Template For Loop with Filtering and Counters
  16. 16.Scenario:
  17. 17.Django Template Tags - Static Files Loading
  18. 18.Django Template Tags - CSRF Protection in Forms
  19. 19.Scenario:
  20. 20.Understanding Django Template Inheritance and Block Tags
  21. 21.Debugging Template Variable Output
  22. 22.Scenario:
  23. 23.Custom Template Filter Implementation
  24. 24.Template Tag with Arguments - Practical Implementation
  25. 25.Scenario:
  26. 26.Conditional Logic and Template Tags
  27. 27.Built-in Template Filters for Data Formatting
  28. 28.For Loop and Loop Variable in Templates
  29. 29.Scenario: