DEV Community

Vincent Tommi
Vincent Tommi

Posted on

Django Interview Questions & Key Concepts – Part 3

1 How do you create a Django-project?
We can create a Django project by the help of the following command:

django-admin startproject  projectname
Enter fullscreen mode Exit fullscreen mode

2 How do you create a django project
we create a django project with help of the following command:

python manage.py startapp appname
Enter fullscreen mode Exit fullscreen mode

3 How do we start development server in python-django
we start development server in python-Django with the help of the following command.

python manage.py runserver
Enter fullscreen mode Exit fullscreen mode

4 what is virtual environment in Django?
A virtual environment is an isolated Python environment that allows you to manage project-specific dependencies separately from the system-wide Python installation. It ensures each Django project can have its own libraries without conflicts. This isolation helps prevent issues when different projects require different versions of the same packages and simplifies deployment by enabling the creation of a requirements.txt file listing all dependencies.

5 What are sessions in Django?
are mechanism that allow storage of user across specific requests.They keep track of the state between a server and particular browser.The session attribute is a dictionary like-object that you can read and write as many times as you like in a view and modifying it as wished.
Django provides a session framework that lets you store and retrieve data on a per-site-visitor basis.

6 Definition of the static files and their importance
refers to unchanging files that are rendered on the browser exactly as they are stored on the server.
These files include ,HTML,CSS,Java-script,images,videos,fonts and documents.They are called server-side since they do not require any server-side processing or dynamic content generation.

7 What is object Relation Mapping(ORM)?
is a technique that allows developers to interact with the databases without writing raw SQL queries with the help of python object and clasess.Provides a high-level intuitive way of working with databases by mapping python object and classes to databases.
Django ORM maybe accessed by running:

python manage.py shell
Enter fullscreen mode Exit fullscreen mode

8 what is a superuser?
superuser is the most powerful user with permission to create, read, delete, and update on the admin page which includes model records and another user. Users of Django have access to an Admin Panel. Before using this feature, you must have to migrate your project; otherwise, the superuser database will not be created. To create a superuser, first, reach the same directory, and run the following command.

python3 manage.py createsuperuser
Enter fullscreen mode Exit fullscreen mode

9 what is jinja templating in django?
is an engine used by django for server-side rendering ,offering a powerful and flexible way to render templates.
it allows embedding dynamic content with HTML templates using placeholders ,control structures,similar to python syntax.
Jinja provides features such as conditional statements, loops, filters, and macros, which help in generating dynamic web pages.
Unlike Django's built-in template engine, Jinja allows the template designer to call functions with arguments on objects, making it more versatile.

10 what's the meaning of csrf_token in django?
CSRF protection is a security feature in Django that prevents cross-site request forgery attacks, where a malicious site tricks a user into performing unwanted actions on another site. Django generates a unique token for each user session, storing it in a cookie and embedding it in forms as a hidden field. When a form is submitted, the server checks if the token in the form matches the one in the cookie. If they match, the request is accepted; if not, it's rejected.

11 what is middleware in Django and what are they used for?
Middleware in Django is a lightweight plugin that processes requests and responses globally. It allows you to modify requests before they reach the view and responses before they’re sent to the client. Django processes requests through a middleware stack defined in the MIDDLEWARE setting, executing middleware in order for requests and in reverse order for responses.

Common uses of middleware include tasks like authentication, authorization, session management, logging, and request/response modification.

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.