Challenge - 5 Problems
Template Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Django view return?
Consider this Django view function. What will the user see when visiting this view?
Django
from django.shortcuts import render def home(request): context = {'name': 'Alice'} return render(request, 'home.html', context)
Attempts:
2 left
💡 Hint
Remember that render combines a template with context data to produce HTML.
✗ Incorrect
The render function takes the request, template name, and context dictionary. It returns an HTML page where placeholders like {{ name }} are replaced by values from the context.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in this Django view
What is wrong with this Django view code?
Django
from django.shortcuts import render def about(request): context = {'page': 'About'} return render('about.html', context)
Attempts:
2 left
💡 Hint
Check the order and number of arguments for render.
✗ Incorrect
The render function requires the request object as its first argument, followed by the template name and context.
❓ state_output
advanced2:00remaining
What is the output HTML of this Django view?
Given this template and view, what HTML will be rendered?
Django
Template 'greet.html': <html><body><h1>Hello, {{ user }}!</h1></body></html> View: from django.shortcuts import render def greet(request): return render(request, 'greet.html', {'user': 'Bob'})
Attempts:
2 left
💡 Hint
Variables in templates are replaced by context values.
✗ Incorrect
The template variable {{ user }} is replaced by the string 'Bob' from the context dictionary passed to render.
🔧 Debug
advanced2:00remaining
Why does this Django view raise TemplateDoesNotExist?
This view raises a TemplateDoesNotExist error. What is the most likely cause?
Django
from django.shortcuts import render def contact(request): return render(request, 'contact_us.html')
Attempts:
2 left
💡 Hint
Check if the template file exists in your templates folder.
✗ Incorrect
The error means Django cannot find the template file named 'contact_us.html' in any of the configured template directories.
🧠 Conceptual
expert2:00remaining
What happens if you return render() without a context?
In Django, what is the behavior when you call
render(request, 'index.html') without providing a context dictionary?Attempts:
2 left
💡 Hint
Check the default value of the context parameter in render.
✗ Incorrect
The render function's context parameter is optional and defaults to an empty dictionary if omitted. The template renders with no variables replaced.