Find Interview Questions for Top Companies
Ques:- save dynamic data without using DB/file.
Right Answer:
You can use in-memory data structures like Python dictionaries or lists to save dynamic data without using a database or file. For example:

```python
data_store = {}

# To save data
data_store['key'] = 'value'

# To retrieve data
value = data_store.get('key')
```
Ques:- what are all reusable application u used in django prjt
Right Answer:
Some reusable applications commonly used in Django projects include:

1. **Django REST Framework** - for building APIs.
2. **Django Allauth** - for authentication and account management.
3. **Django Crispy Forms** - for better form rendering.
4. **Django Debug Toolbar** - for debugging during development.
5. **Django Celery** - for handling asynchronous tasks.
6. **Django Storages** - for integrating with cloud storage services.
7. **Django Haystack** - for search functionality.
8. **Django Filter** - for filtering querysets easily.
Ques:- How to get all logged-in user list or count
Right Answer:
To get the count of all logged-in users in Django, you can use the `Session` model to filter sessions that are currently active. Here's a simple way to do it:

```python
from django.contrib.sessions.models import Session
from django.utils import timezone

# Get all active sessions
active_sessions = Session.objects.filter(expire_date__gte=timezone.now())

# Count of logged-in users
logged_in_user_count = active_sessions.count()
```

To get a list of logged-in users, you can extract the user IDs from the sessions:

```python
logged_in_users = [session.get_decoded().get('_auth_user_id') for session in active_sessions]
```
Ques:- Have you write templatetags? Whats the use of it?
Right Answer:
Yes, I have written custom template tags in Django. They are used to create reusable code snippets that can be used in templates to perform specific functions, such as formatting data or including complex logic directly within the template.
Ques:- what is signals and how to use it? What are two important parameter in signals?
Right Answer:
In Django, signals are a way to allow certain senders to notify a set of receivers when some action has taken place. They are used to decouple applications by allowing different parts of an application to communicate without being tightly coupled.

To use signals, you typically connect a receiver function to a signal using the `@receiver` decorator or the `connect()` method.

Two important parameters in signals are:
1. `sender`: The model class that sends the signal.
2. `instance`: The actual instance of the model that triggered the signal.
Ques:- Django group_by query
Right Answer:
In Django, you can use the `annotate()` and `values()` methods to perform a group by query. Here's an example:

```python
from django.db.models import Count
from your_app.models import YourModel

result = YourModel.objects.values('field_to_group_by').annotate(count=Count('id'))
```

This will group the records by `field_to_group_by` and count the number of occurrences for each group.
Ques:- how you will write django complex query?
Right Answer:
To write a complex query in Django, you can use the `Q` objects for complex lookups and chaining filters. For example:

```python
from django.db.models import Q
from myapp.models import MyModel

# Example of a complex query
results = MyModel.objects.filter(
Q(field1__icontains='value1') | Q(field2__gte=10)
).exclude(field3='value2').order_by('-field4')
```

This query filters `MyModel` instances where `field1` contains 'value1' or `field2` is greater than or equal to 10, excludes those with `field3` equal to 'value2', and orders the results by `field4` in descending order.
Ques:- how you used session ? How can we handle session expire time ?
Right Answer:
In Django, you can use sessions by accessing the `request.session` dictionary to store and retrieve data. To handle session expiration time, you can set the `SESSION_COOKIE_AGE` setting in your `settings.py` file, which defines the duration (in seconds) before a session expires. For example, to set a session to expire after 30 minutes, you would use:

```python
SESSION_COOKIE_AGE = 1800 # 30 minutes
```
Ques:- what are all middleware you used and whats the purpose ot it?
Right Answer:
Some common middleware used in Django include:

1. **SecurityMiddleware**: Adds security-related headers to responses.
2. **SessionMiddleware**: Manages user sessions across requests.
3. **AuthenticationMiddleware**: Associates users with requests, enabling user authentication.
4. **MessageMiddleware**: Enables temporary message storage for user notifications.
5. **CommonMiddleware**: Provides various utilities, such as URL normalization and handling of empty GET/POST data.
6. **CsrfViewMiddleware**: Protects against Cross-Site Request Forgery attacks by adding CSRF tokens.

Each middleware serves a specific purpose in processing requests and responses in a Django application.
Ques:- how you will add extra function/feature in admin part
Right Answer:
To add an extra function or feature in the Django admin, you can override the `ModelAdmin` class for your model. You can define custom methods and add them as actions, or you can customize the admin form by using `form` attribute in your `ModelAdmin`. Additionally, you can use `list_display`, `search_fields`, and `list_filter` to enhance the admin interface. Finally, register your model with the customized `ModelAdmin` class using `admin.site.register()`.
Ques:- What is the use of manage.py
Right Answer:
`manage.py` is a command-line utility in Django that allows you to interact with your Django project. It helps you run server commands, manage database migrations, create applications, and perform various administrative tasks.
Ques:- what is __init__.py inisde application folder?
Right Answer:
`__init__.py` is a special Python file that indicates to Python that the directory it is in should be treated as a package. In a Django application folder, it allows the application to be recognized as a module, enabling the import of its components.
Ques:- How django works (work flow)
Right Answer:
Django works through the following workflow:

1. **Request**: A user makes a request to the Django server via a URL.
2. **URL Routing**: Django uses the URL dispatcher to match the request URL to a specific view function.
3. **View Processing**: The matched view function processes the request, interacts with the database if needed, and prepares a response.
4. **Template Rendering**: If the view returns HTML, Django uses templates to render the final HTML response.
5. **Response**: Django sends the generated response back to the user's browser.

This cycle continues for each request made to the server.
Ques:- Explain the architecture of Django?
Right Answer:
Django follows the Model-View-Template (MVT) architecture:

1. **Model**: Defines the data structure and interacts with the database. It represents the data layer of the application.
2. **View**: Contains the business logic and handles user requests. It retrieves data from the model and passes it to the template.
3. **Template**: Manages the presentation layer. It defines how the data is displayed to the user.

Django also includes a URL dispatcher that maps URLs to views, and it follows the "Don't Repeat Yourself" (DRY) principle to promote code reusability.
Ques:- What do you understand by Django?
Right Answer:
Django is a high-level Python web framework that simplifies the development of web applications by providing built-in features such as an ORM (Object-Relational Mapping), an admin interface, and tools for handling user authentication, URL routing, and form processing. It follows the MVC (Model-View-Controller) architectural pattern and promotes rapid development and clean, pragmatic design.


The Python category on takluu.com is tailored for learners and professionals who want to build a strong foundation in one of the most popular programming languages today. Python’s simplicity and readability make it an excellent choice for beginners, while its powerful libraries and frameworks attract experts working in diverse fields like web development, data analysis, artificial intelligence, and automation.

This section covers core Python concepts such as data types, control structures, functions, modules, object-oriented programming, exception handling, and file operations. You will also explore advanced topics like libraries (NumPy, Pandas), web frameworks (Django, Flask), and automation scripting.

Having a good grasp of Python is invaluable in today’s job market, especially for roles in software development, data science, machine learning, and DevOps. Interviewers often test your understanding of Python basics as well as your ability to solve real-world problems using Python code.

At Takluu, we provide clear explanations, practical coding examples, and common interview questions to help you gain confidence and improve your programming skills. Whether you’re starting from scratch or looking to polish your Python knowledge, this category is your go-to resource for success.

Master Python with us, and open doors to exciting career opportunities in technology and beyond.

AmbitionBox Logo

What makes Takluu valuable for interview preparation?

1 Lakh+
Companies
6 Lakh+
Interview Questions
50K+
Job Profiles
20K+
Users