Django Flashcards
30 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 Django flashcards as text
In the fall of what year was Django created?
Answer: 2003
Django was created in the fall of 2003 by a web team at the Lawrence Journal-World newspaper. It was initially developed to power several news-related websites. The framework was later publicly released under a BSD license in July 2005.
What is MVT stand for?
Answer: Model-View-Template
Django follows the Model-View-Template (MVT) architectural pattern, which is a variation of the Model-View-Controller (MVC) pattern. In MVT, the Model handles data logic, the View handles the business logic and interacts with the Model, and the Template handles the presentation logic to display data to the user. This structure helps in separating concerns within a Django application.
Which of the following can be a view response?
Answer: All of the above
A Django view function is responsible for processing a web request and returning an HTTP response. This response can take various forms, including rendered HTML content, JSON or XML data, redirects, or HTTP error codes like a 404 Not Found. Django's `HttpResponse` class and its subclasses provide the flexibility to return any of these types of responses.
Django is a Python web framework with a _______________.
Answer: high-level
Django is considered a 'high-level' Python web framework because it handles much of the boilerplate code and common web development tasks for you. It provides many built-in features and conventions, such as an ORM, admin interface, and templating system, allowing developers to build complex applications rapidly with less code. This abstraction makes it easier to focus on application logic rather than low-level details.
If you need to deploy your project using WSGI, which of the following is used?
Answer: wsgi.py
The `wsgi.py` file in a Django project contains the WSGI (Web Server Gateway Interface) application object. This file serves as the entry point for WSGI-compatible web servers (like Gunicorn, uWSGI, or Apache with mod_wsgi) to communicate with your Django application, allowing it to serve requests in a production environment.
In Django, how many various kinds of HTTP requests are there?
Answer: 2
While HTTP defines several request methods (GET, POST, PUT, DELETE, etc.), in the context of typical web forms and basic interactions, Django primarily distinguishes between two main types of requests: GET and POST. GET requests are used to retrieve data and are idempotent, while POST requests are used to submit data and can have side effects. Django's `request.method` attribute allows you to easily check for these two common types.
In Django, a variable appears as __________________.
Answer: {{variable}}
Django's template language uses a specific syntax for displaying variables. Variables are enclosed in double curly braces, like `{{ variable_name }}`, which tells the template engine to render the value of that variable at that position. This is a fundamental part of how data is passed from Django views to HTML templates.
What features does the Django web framework have?
Answer: All of the above
Django is known for being a 'batteries-included' framework, offering a comprehensive set of features out-of-the-box. This includes a powerful templating system for rendering dynamic HTML, an automatic and highly customizable admin interface for managing data, and robust form handling capabilities for processing user input. These features collectively streamline web development.
There are _____________ components to the MVC pattern.
Answer: three
The Model-View-Controller (MVC) architectural pattern, which Django's MVT pattern is based on, fundamentally consists of three interconnected components. The Model manages data and business logic, the View presents data to the user, and the Controller handles user input and orchestrates interactions between the Model and View.
What are some valid Django Template System forloop attributes?
Answer: forloop.counter
Inside a `{% for %}` loop in Django templates, several special variables are available to provide information about the loop's progress. `forloop.counter` is a valid attribute that returns the current iteration of the loop (1-indexed). Other common attributes include `forloop.counter0` (0-indexed), `forloop.first`, `forloop.last`, and `forloop.parentloop`.
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.
In production, which of the following is not utilized as a Django server?
Answer: Ansible
Gunicorn, uWSGI, and Mod_WSGI are all common WSGI servers or adapters used to serve Django applications in production environments. They act as an interface between the web server (like Nginx or Apache) and the Django application. Ansible, on the other hand, is an automation engine used for configuration management, application deployment, and task automation, not for serving web applications directly.
In Django admin, which attribute is applied to order the objects?
Answer: ordering
In Django's admin interface, you can customize how objects are displayed and ordered in the list view. To specify the default sorting order for a model's objects, you use the `ordering` attribute within the `Meta` class of your model. This attribute takes a tuple or list of field names, optionally prefixed with a hyphen for descending order.
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.
What happens if you make changes to the url.py file while the development server is still running?
Answer: The development server automatically restarts.
Django's development server (run with `python manage.py runserver`) includes an auto-reloader feature. When it detects changes to Python source code files, including `urls.py`, `models.py`, `views.py`, or `settings.py`, it automatically restarts itself. This convenient feature allows developers to see their changes reflected without manually stopping and starting the server.
What is the purpose of the {# #} template?
Answer: It is comment in template language.
In Django's template language, `{# #}` is used to denote comments. Any text placed between `{#` and `#}` will be ignored by the template engine and will not be rendered in the final output HTML. This allows developers to add explanatory notes or temporarily disable parts of the template code without affecting the page's content.
In urls.py, what method is used instead of path() to pass regular expressions as routes?
Answer: url()
In older versions of Django (prior to 2.0), the `url()` function was the primary way to define URL patterns using regular expressions. While Django 2.0 introduced `path()` for simpler string-based routing, and `re_path()` as its modern regex-based counterpart, `url()` historically served the purpose of allowing developers to specify complex routes using regular expressions.
In Django, what is the default time zone?
Answer: America/Chicago
By default, Django projects are configured to use `America/Chicago` as their time zone. This setting is defined in the `TIME_ZONE` variable within the `settings.py` file. While it can be changed to any valid time zone string, `America/Chicago` is the out-of-the-box default for new projects.
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.
Which of the following is a method for preventing Denial of Service attacks?
Answer: Traffic Filtering
Traffic filtering is a crucial method for preventing Denial of Service (DoS) attacks by inspecting incoming network traffic and blocking malicious or suspicious packets. This involves identifying and dropping traffic that matches known attack patterns, originates from suspicious IP addresses, or exceeds predefined rate limits. By filtering out unwanted traffic, legitimate requests can still reach the server, maintaining service availability.
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