Django Theory
Django Theory
_____________________
2. features of Django?
A. . rapid development
. Security
. Scalability
. Versatility
. open source
. large community
3. Disadvantages of Django?
. Limited Flexibility
A. When a user sends a request from the browser to the server, Django first checks
the URL. The URL maps to a specific view function, which
interacts with the model to retrieve or manipulate data. After processing the
http request, the view returns an HTTP response. Django follows
the Model-View-Template (MVT) pattern, where the model defines the data
structure of the application. Models, represented as Python classes,
interact with the database, defining how data is stored and retrieved. Views
handle HTTP requests and responses, containing the business logic
to retrieve data from models and pass it to templates for rendering. Templates
in Django are HTML files that receive data from views and display
it to the user.
5. what is url?
A. A URL, standing for Uniform Resource Locator, serves as a mapping between a user
request and view functions. It defines the structure of a web
application's URLs, enabling users to access different parts of the application.
In Django, URLs are commonly defined in a Python module called
'urls.py' within each Django app.
A. HTTP decorators are special functions used to modify the behavior of view
functions. They provide additional functionality, such as
authentication, permissions, or caching, to views easily. Some commonly used
HTTP decorators in Django include:
. @login_required
. @permission_required
. @csrf_exempt
. @require_http_methods
. @cache_control
A. . Project Directory: This is the main directory containing your entire Django
project. It typically has the same name as your project.
. manage.py: This command-line server interacts with your Django project. You
can use it to run the development server, create migrations, and
perform various other tasks.
. urls.py: This file contains URL patterns for your Django project. It maps URL
paths to view functions.
. App: This directory contains one or more Django apps, each representing a
specific functionality or feature of your project.
. Static Files: The 'static' directory contains CSS, JavaScript, images, and
other static assets used by your project.
. Templates: This directory contains HTML template files used to render dynamic
content in your Django project.
A. Django's template language is a simple but powerful language that allows you to
generate dynamic HTML pages by using placeholders for variables
and adding custom logic to your templates.
. Variables: Variables are used to display data from the Django view. They are
enclosed in double curly braces, e.g., {{ variable_name }}.
. Tags: Tags are used to perform operations like looping, conditional rendering,
or loading other templates. They are enclosed in {% %} blocks,
e.g., {% for item in item_list %} or {% if condition %}.
. Filters: Filters modify the output of variables or tags. They are applied
using the pipe character | For example, {{ value|lower }}.
. Comments: Comments in Django templates are enclosed in {# #} blocks, e.g., {#
This is a comment #}.
A. views are Python functions or classes that handle the logic for processing
requests and generating responses for web pages. there are two types
of views:
A. Django static files are files served directly to the user's browser, such as
CSS, JavaScript, and image files. They are not dynamically
generated but can be used in Django templates.
A.
What is an API?
Django Rest Framework lets you create RESTful APIs: A way to transfer information
between an interface and a database in a simple way.
A. . project:- project is the entire web application. It contains the settings, URL
configurations, and overall structure of the application. A
project can consist of one or more apps. Projects are created using the
Django-admin startproject command.
A. there are three main model inheritance styles that allow you to reuse code and
establish relationships between models.
. abstract base class:- An abstract base class is like a template that holds
shared information for multiple child models. It's not used to
create database tables itself, but other models can inherit its fields and
methods.
. Multi-table inheritance:- it means each model has its own table in the
database. The child model is linked to the parent model through a one-
to-one relationship.
. Proxy models offer a way to make a copy of an existing model without creating
a new table in the database. They work just like regular models
but share the same table as the original model.
A. Migrations are a way to manage changes in the database schema. When you make
changes to models, such as adding new fields or modifying existing
ones, Django creates migration files to represent these changes. These files are
generated by the makemigrations command.
The migrate command is used to apply these changes to the database schema. Once
you have created migration files, you can use the migrate
command to execute them and update the database schema.
A. Database connections are managed through the settings.py file of your project in
Django. Django uses the DATABASES setting to define the
configuration for connecting to one or more databases, such as PostgreSQL,
MySQL, SQLite, and Oracle. This setting typically includes details
such as the database engine, database name, username, password, host, and port.
A. HTTP stands for Hypertext Transfer Protocol. It is used for transmitting data
over the World Wide Web and forms the foundation of data
communication on the internet. HTTP allows clients to request and receive
resources from web servers.
. Status: The status line includes the HTTP version and a status code,
indicating the outcome of the request.
. Body: The body contains the actual data or resource being sent back to the
client, such as an HTML document, an image, JSON data, or any other
content type.
. 400 Bad Request: Invalid syntax, server can't understand the request.
. 500 Internal Server Error: Unexpected server error during request processing.
27. stateless?
. Cookies:- Cookies are tiny pieces of data stored on the user's browser by the
server. They can save user preferences, track activity, and
maintain session info.
A. Channels are a way to handle real-time web applications and asynchronous tasks.
They enable Django to support protocols like WebSockets,
allowing bidirectional communication between the client and server in real time.
It provide functionality for handling events, such as instant
messaging, notifications, or live updates.
31. webserver?
A. A web server is a software application that handles incoming HTTP requests from
clients (web browser) and provides corresponding responses. Its
primary function is to serve web content, such as HTML pages over the internet.
A. A context processor in Django is a Python function that adds data to the context
for every template rendering. These functions can be defined in
any Python module accessible to Django. They are registered in the Django
settings file (settings.py) within the TEMPLATES configuration.
A. Virtual environments provide isolation for Python projects, ensuring that each
project has its own set of dependencies and Python interpreter.
This isolation helps prevent conflicts between dependencies used in different
projects and ensures that each project operates independently.