0% found this document useful (0 votes)
25 views

Django Theory

Theory of some django topics

Uploaded by

1968fathimapa
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Django Theory

Theory of some django topics

Uploaded by

1968fathimapa
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

DJANGO THEORY

_____________________

1. what is Django and why Django?

A. Django is a high-level Python web framework. It is free and open source. it is


used for building web applications using the Python
programming language. It follows the Model-View-Template (MVT) architectural
pattern, enabling rapid development of secure and maintainable
web applications. Django makes it easier to build better web apps more quickly
and with less code.

2. features of Django?

A. . rapid development

. Security

. Easy to interact with database

. Scalability

. Versatility

. open source

. large community

3. Disadvantages of Django?

A. . Django can take some time to learn

. Limited Flexibility

. Less Suitable for SPAs (single page applications)

. May be slower for simpler applications.

. Django's structure might not fit well with a microservices architecture.

4. how does Django is works?

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.

6. Django view http decorators?

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

7. explain the Django project directory structure?

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.

. Settings.py: This file contains configuration settings for your Django


project. Settings such as database configuration, installed apps,
middleware, and static files configuration are defined here.

. 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.

8. Django template language?

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 #}.

9. what are view in Django?

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:

. Function-based views:- Function-based views in Django are Python functions


that process requests and return responses. They handle the
logic for specific URL patterns and sometimes work with models to get or
change data.

. Class-based views:- Class-based views in Django are Python classes that


inherit from built-in view classes like View, TemplateView,
ListView, and DetailView. They offer an object-oriented approach and
sometimes include mixin for reusable code.

10. what is Django orm?

A. Django ORM (Object-Relational Mapping) is a powerful feature that allows


developers to interact with databases using Python objects. It
abstracts the database layer and provides a high-level API for performing
database operations, such as creating, reading, updating, and deleting
records, without writing SQL queries directly.

11. define static file and their uses?

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.

12. what is Django rest framework?

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.

13. difference between project and app?

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.

. app:- app is a reusable component of the project.it consists of models,


views, templates, and static files. consists of models, views,
templates, and static files.

14. what is Django-admin and manage.py and explain it commands?

A. Django-admin:- Django-admin is a command-line utility that allows developers to


interact with Django projects. It provides various commands for
creating and managing Django projects and applications. Some common commands
include:
. startproject: Creates a new Django project.

. startapp: Creates a new Django app within a project.

manage.py:manage.py is a Python script automatically generated in every Django


project. It provides a command-line interface to interact with
various Django management commands. Some common commands include:

. runserver: Starts the Django development server.

. makemigrations: Generates database migration files based on changes to


models.

. migrate: Applies database migrations to update the database schema.

. createsuperuser: Creates a superuser account.

15. what is jinja template?

A. Jinja is a popular templating engine for Python web development. It provides a


way to generate dynamic content in web applications by combining
HTML templates with Python code. jinja templates support features like template
inheritance, macros, filters, loops, and conditionals, providing
powerful tools for creating reusable and maintainable templates.

16. what are the different model inheritance style in Django?

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.

17. what are Django signals?

A. Signal is a mechanism for intercepting and responding to events or actions that


occur within the ORM (Object-Relational Mapping) system. Signals
are often used to customize and automate the behavior of an ORM framework based
on specific events, such as database record creation, updating,
or deletion. They are implemented at the application level and allow developers
to define custom actions when certain events happen.

18. middleware in Django?

A. Middleware in web development refers to a software component that sits between


the client and the web application. Middleware processes and
manipulates HTTP requests and responses as they travel between the client and
the web server, adding an extra layer of functionality to the web
application.

19. what is csrf in Django

A. A CSRF token in Django is a security measure used to protect against CSRF


attacks. It is a unique token that prevents unauthorized requests from
malicious websites. It's like a secret code that only the user's browser and the
Django server know. When a user interacts with a form or sends
data, this token ensures that the request is coming from a trusted source. If
the token doesn't match what the server expects, the request is
rejected, protecting against CSRF attacks.

20. migration and migrate in Django?

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.

21. what is database connection?

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.

22. what is http?

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.

23. parts of http response?

A. An HTTP response consists of three parts:

. Status: The status line includes the HTTP version and a status code,
indicating the outcome of the request.

. Headers: Headers provide additional information about the response, such as


the content type, content length, cookies, and server details.
Headers are key-value pairs separated by a colon (:).

. 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.

24. http method?

A. . GET: Retrieves data from the server.

. POST: Submits data to the server.


. PUT: Updates an existing resource on the server.

. PATCH: Partially updates an existing resource.

. DELETE: Removes a resource from the server.

25. render and redirect?

A. . Render:- Rendering involves generating a response that includes HTML content


based on a template. This means dynamically generating HTML
content on the server-side and sending it back to the client.

. Redirect:- Redirecting means instructing the client's browser to make a new


request to a different URL. This is used when the server needs to
direct the client to another location.

26. status code?

A. . 200 OK: Request successful.

. 400 Bad Request: Invalid syntax, server can't understand the request.

. 401 Unauthorized: Client needs authentication for access.

. 404 Not Found: Requested resource not found.

. 500 Internal Server Error: Unexpected server error during request processing.

27. stateless?

A. HTTP is a stateless protocol, which means servers do not need to maintain


constant connections or session data for individual clients. Instead,
clients include all necessary information in each request, enabling servers to
process requests independently and efficiently."

28. session and cookies?

A. . Session:- Sessions store user-specific data on the server-side across multiple


requests. When a user interacts with a web app, a session is
created and gets a unique ID. This ID is stored in a cookie on the user's
browser and sent with each request to the server.

. 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.

29. channel in Django?

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.

30. queryset in Django?

A. a queryset is a powerful tool used to interact with the database. It represents


a collection of database query results and allows you to filter,
retrieve, update, or delete data from the database using Python code.

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.

32. context processor?

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.

33. cors in Django?

A. CORS (Cross-Origin Resource Sharing) is a browser security feature in web


application development. It ensures that resources from one domain can be safely
accessed by web applications hosted on another domain, thus increasing security
measures.

34. virtual environment

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.

You might also like