0
0
Djangoframework~20 mins

How Django processes a request (URL → View → Template) - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Django Request Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when Django matches a URL pattern?
When a user visits a URL, Django tries to find a matching pattern in the URL configuration. What is the next step after Django finds a matching URL pattern?
ADjango immediately renders the template without calling any view.
BDjango calls the associated view function or class to handle the request.
CDjango sends a 404 error response to the user.
DDjango directly queries the database for data.
Attempts:
2 left
💡 Hint
Think about what Django does to process the request after matching the URL.
state_output
intermediate
2:00remaining
What does a Django view typically return?
Consider a simple Django view function. What is the usual type of object that a Django view returns to complete the request?
Django
def my_view(request):
    # some logic here
    return ???
AA Python dictionary with data only.
BA URL string to redirect the user.
CAn HttpResponse object containing the content to send back to the browser.
DA database query set.
Attempts:
2 left
💡 Hint
Think about what Django needs to send back to the browser.
📝 Syntax
advanced
2:00remaining
Identify the correct way to render a template in a Django view
Which of the following code snippets correctly renders a template named 'home.html' with a context dictionary in a Django view?
Areturn render(request, 'home.html', {'name': 'Alice'})
Breturn render_to_response('home.html', {'name': 'Alice'})
Creturn HttpResponse('home.html', {'name': 'Alice'})
Dreturn render_template('home.html', {'name': 'Alice'})
Attempts:
2 left
💡 Hint
Look for the modern Django shortcut function that takes request, template name, and context.
🔧 Debug
advanced
2:00remaining
Why does this Django view raise a TemplateDoesNotExist error?
Given this view code, why does Django raise a TemplateDoesNotExist error when accessing the URL? ```python def my_view(request): return render(request, 'dashboard.html') ``` Assuming 'dashboard.html' exists in the templates folder.
Django
def my_view(request):
    return render(request, 'dashboard.html')
AThe templates folder is not configured correctly in settings.py.
BThe view forgot to pass a context dictionary to render.
CThe URL pattern is missing for this view.
DThe render function is missing the request argument.
Attempts:
2 left
💡 Hint
Check if Django knows where to find templates.
🧠 Conceptual
expert
3:00remaining
Order of Django request processing steps
Put these Django request processing steps in the correct order from when a user sends a request to when the response is sent back:
A3,1,2,4
B2,1,3,4
C1,3,2,4
D1,2,3,4
Attempts:
2 left
💡 Hint
Think about the natural flow from URL to view to template to response.