โ† All Django Flashcard Decks

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
  1. What is the difference between a function-based view (FBV) and a class-based view (CBV) in Django?

    Answer: FBVs are plain functions; CBVs are classes that inherit from Django view classes

    FBVs are Python functions taking a request and returning a response, while CBVs are classes that provide built-in mixins and method dispatch for HTTP verbs.

  2. Which decorator restricts a view to logged-in users only?

    Answer: @login_required

    @login_required redirects unauthenticated users to the login page and is imported from django.contrib.auth.decorators.

  3. What does `path()` do in Django's URL configuration?

    Answer: Maps a URL pattern to a view function or class

    path() is used in urls.py to associate a string-based URL pattern with a view, supporting type converters like .

  4. How do you capture a URL parameter as an integer in Django's path() routing?

    Answer:

    Angle brackets with a type converter like capture and automatically convert the URL segment to a Python integer.

  5. Which HttpResponse subclass performs a permanent redirect in Django?

    Answer: HttpResponsePermanentRedirect

    HttpResponsePermanentRedirect returns a 301 status code, while HttpResponseRedirect returns a 302 temporary redirect.

  6. What function reverses a URL pattern by name in Django?

    Answer: reverse()

    reverse() takes a URL name and optional arguments to generate the corresponding URL string, avoiding hardcoded URLs.

Written and edited by , 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