← All Django Flashcard Decks

Mixed Deck — All Django Topics Flashcards

100 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 20 Mixed Deck — All Django Topics flashcards as text
  1. Which setting controls whether detailed error pages are shown to users?

    Answer: DEBUG

    DEBUG should be False in production to avoid leaking sensitive error details.

  2. Which class should a Django test case inherit from to get database access and automatic rollback between tests?

    Answer: django.test.TestCase

    django.test.TestCase wraps each test in a transaction that is rolled back after the test, providing database isolation.

  3. Which assertion method should you use to verify that a Django view returns a redirect response?

    Answer: self.assertRedirects(response, '/expected-url/')

    assertRedirects checks both the redirect status code and the final redirect target URL in one call.

  4. Which abstract base class makes a model function as an abstract base, not creating its own database table?

    Answer: Setting abstract = True in Meta

    Setting abstract = True in the model's Meta class tells Django not to create a database table for that model; subclasses get their own tables with inherited fields.

  5. In a Django model, which field type is best for storing a large block of multi-line text?

    Answer: TextField

    TextField stores unbounded multi-line text, unlike CharField which requires max_length.

  6. Which Django template filter converts a string to all uppercase?

    Answer: upper

    The upper filter converts all characters in the string to uppercase, e.g., {{ 'hello'|upper }} outputs 'HELLO'.

  7. What does `form.as_p()` do in Django?

    Answer: Renders the form fields wrapped in HTML tags

    as_p() is a convenience method that renders all form fields and labels wrapped in elements, providing quick HTML output.

  8. What does marking a variable with `{{ value|safe }}` do in Django templates?

    Answer: Disables auto-escaping for that variable, rendering raw HTML

    The safe filter tells Django's template engine to trust the variable's content and render it as raw HTML without escaping, which should only be used with trusted data.

  9. What does the `{% url 'viewname' %}` template tag do?

    Answer: Generates a URL for the named view, reversing the URL pattern

    {% url %} calls Django's reverse() function at template render time to produce the correct URL for a named view, avoiding hardcoded paths.

  10. What is the best way to exclude a specific field from a ModelForm?

    Answer: Use the exclude parameter in the Meta class in your form

    When creating a `ModelForm` in Django, you can easily control which fields from the associated model are included or excluded. The most straightforward and recommended way to exclude specific fields is by defining an `exclude` tuple within the `Meta` class of your `ModelForm`, listing the names of the fields you wish to omit. This keeps the form concise and aligned with your model while providing flexibility.

  11. The current input as well as the previous output states determine the output of a circuit. ___________________ is the term given to the circuit.

    Answer: Sequential circuit

    This question describes a fundamental characteristic of a sequential circuit in digital electronics. Unlike combinational circuits whose output depends only on the current inputs, a sequential circuit's output is determined by both its current inputs and its past history, which is stored in its internal state. This memory element allows sequential circuits to perform more complex operations, such as counting or storing data.

  12. What is a small template that contains details from the current object?

    Answer: Inclusion tags

    Inclusion tags are a type of custom template tag in Django that render another template with data from the current context. They are particularly useful for displaying small, reusable pieces of information, such as details about an object passed to the tag, without cluttering the main template logic. This allows for better organization and reusability of template components.

  13. What Django command should you use to see the database of an existing or legacy?

    Answer: manage.py inspectdb

    The `manage.py inspectdb` command is used in Django to introspect an existing database and output a Django model definition for each table. This is particularly useful when working with a legacy database that was not created by Django, as it helps generate the initial `models.py` file. It allows developers to quickly integrate an existing database into a Django project without manually writing all model classes.

  14. Which filter formats a number with commas as thousands separators in Django templates?

    Answer: intcomma

    The intcomma filter from django.contrib.humanize formats integers with commas, e.g., 1000000 becomes 1,000,000; requires {% load humanize %}.

  15. Which Django setting controls password hashing algorithms?

    Answer: PASSWORD_HASHERS

    PASSWORD_HASHERS is a list of hasher classes in priority order; Django uses the first one for new passwords and can upgrade older hashes automatically.

  16. What does `login(request, user)` do in Django?

    Answer: Attaches the user to the session and marks them as logged in

    login() saves the user's ID to the session using Django's session framework, establishing the logged-in state across requests.

  17. What does `form.save()` do on a Django ModelForm?

    Answer: Creates or updates the model instance based on the form's cleaned data

    ModelForm.save() creates a new instance or updates an existing one (if bound to an instance) using the validated cleaned_data.

  18. Which DRF pagination class splits results into pages of a fixed size?

    Answer: PageNumberPagination

    PageNumberPagination splits querysets into pages accessed via a page query parameter, configurable with PAGE_SIZE in DEFAULT_PAGINATION_CLASS settings.

  19. What does the `unique=True` argument on a model field enforce?

    Answer: That no two rows can have the same value for that field

    Setting unique=True creates a UNIQUE constraint in the database, ensuring no two model instances share the same field value.

  20. What does setting `required=False` on a Django form field do?

    Answer: Makes the field optional so empty values pass validation

    By default form fields require a non-empty value; required=False allows the field to be submitted empty without triggering a validation error.

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