Django Views & URLs Flashcards
6 cards from real Django practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 Django Views & URLs flashcards as text
What is Django middleware?
Answer: A framework of hooks that processes requests and responses globally before reaching views
Middleware is a series of hooks in Django's request/response lifecycle that allows global processing such as authentication, session handling, and CSRF protection.
Which response object should a view return to send JSON data in Django?
Answer: JsonResponse
JsonResponse is a subclass of HttpResponse that serializes a dictionary to JSON and sets the Content-Type to application/json automatically.
What does the `kwargs` parameter in a Django URL pattern represent?
Answer: Additional keyword arguments passed to the view from the URL configuration
URL patterns can pass extra keyword arguments to views using the third argument in path(), allowing contextual data beyond URL captures.
How do you define a URL namespace in Django to avoid name collisions between apps?
Answer: Set app_name in the app's urls.py or use namespace= in include()
Defining app_name = 'myapp' in urls.py or passing namespace='myapp' to include() allows you to reference URLs as 'myapp:viewname'.
Which Django view class is best for displaying and processing a single model's create form?
Answer: CreateView
CreateView provides built-in form rendering, validation, and object creation for a model, requiring only model, fields, and success_url.
What HTTP status code does Django's `Http404` exception result in?
Answer: 404
Raising Http404 causes Django to return a 404 Not Found response, optionally rendering a custom 404.html template.
Written and edited by Nathan Beja, founder of Practice Test Geeks, with AI assistance. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Editorial policy