Day 2
Day 2
Day 3)
DAY 1
1. What is Django?
Explanation:
Django is a Python web framework that lets you build websites quickly with less code. It
follows the MVT (Model-View-Template) architecture. It comes with built-in tools like
admin panel, authentication, ORM, and more.
Theory Questions:
1. What is Django?
2. What language is Django written in?
3. What architecture does Django follow?
4. Is Django open-source?
5. Which companies use Django?
Practical Questions:
1. Install Django and create a project.
2. Run Django server and open localhost:8000.
3. Create a new app in Django.
4. Register the app in settings.py.
5. Explore the Django folder structure.
---
2. Features of Django
Explanation:
- Fast development
- Secure (built-in protection from attacks)
- Scalable
- Portable (runs anywhere)
- Admin panel
- ORM support
- Reusable apps
Theory Questions:
1. List any three Django features.
2. What helps Django interact with the database?
3. Why is Django secure?
4. What does the admin panel do?
5. Is Django good for big apps?
Practical Questions:
1. Create a model and access it in admin.
2. Use ORM to add and fetch data.
3. Set up static files in Django.
4. Create and use templates.
5. Add built-in authentication.
---
3. What is a Framework?
Explanation:
A framework is a pre-built structure for developing apps faster. Django provides a ready-
made system to build websites instead of building everything from scratch.
Theory Questions:
1. What is a software framework?
2. Name two Python frameworks.
3. What kind of framework is Django?
4. Framework vs Library?
5. Why use frameworks?
Practical Questions:
1. Create a Django project.
2. Explore files created by startproject.
3. Add and configure a new app.
4. Use a built-in feature like admin.
5. Compare raw Python project with Django.
---
Theory Questions:
1. What is the architecture of Django?
2. What does Model do?
3. Role of View?
4. What part handles UI?
5. How does data flow in Django?
Practical Questions:
1. Create a model.
2. Create a view.
3. Create a template and connect to view.
4. Use model data in the template.
5. Create a full flow: URL → View → Template.
---
5. MVT vs MVC
Explanation:
- Django uses MVT (Model, View, Template)
- MVC = Model, View, Controller
Theory Questions:
1. What does MVT stand for?
2. What is the Controller in Django?
3. Difference between Template and View?
4. Is Django using MVC or MVT?
5. Why is MVT useful?
Practical Questions:
1. Create full MVT flow.
2. Create two templates and switch views.
3. Print model data in template.
4. Use class-based view instead of function.
5. Create another app with same pattern.
---
6. What is HTTP?
Explanation:
HTTP (HyperText Transfer Protocol) is the protocol used to transfer data between browser
and server. It's stateless.
Theory Questions:
1. What is HTTP?
2. Is HTTP stateful?
3. Who uses HTTP?
4. What are HTTP methods?
5. How does a browser communicate with a server?
Practical Questions:
1. Send GET request in browser.
2. Create a Django view to return HTML.
3. Use Postman to send POST request.
4. Inspect network tab in browser.
5. Return JSON response in Django.
---
7. HTTP Methods
Explanation:
- GET: Read data
- POST: Create data
- PUT: Replace data
- PATCH: Update partial data
- DELETE: Remove data
Theory Questions:
1. Name five HTTP methods.
2. Which method updates data?
3. GET vs POST?
4. Which method deletes?
5. Are methods case-sensitive?
Practical Questions:
1. Create a view for GET and POST.
2. Use Postman for PATCH request.
3. Use curl to DELETE.
4. Handle PUT in DRF view.
5. Log method type in view.
---
8. HTTP Request Format
Explanation:
- Request line: Method, URL, HTTP version
- Headers: Info about request
- Body: Only for POST/PUT/PATCH
Theory Questions:
1. Parts of HTTP request?
2. Is body included in GET?
3. What are headers for?
4. What does request line contain?
5. Where is form data?
Practical Questions:
1. View request in browser dev tools.
2. Print headers in Django view.
3. Read form data from POST.
4. Inspect request in Postman.
5. Log full request.
---
Theory Questions:
1. Parts of HTTP response?
2. What is in status line?
3. What does header contain?
4. Can response have no body?
5. Meaning of 404?
Practical Questions:
1. Return HTML response.
2. Return JSON using JsonResponse.
3. Check headers in browser.
4. Test response in Postman.
5. Set custom header.
---
Theory Questions:
1. CRUD full form?
2. What does POST do?
3. Which method deletes?
4. Difference between PUT and PATCH?
5. What maps to READ?
Practical Questions:
1. Create views for CRUD.
2. Test with Postman.
3. Form with POST to create data.
4. Update using PUT.
5. Delete using DELETE.
DAY 2
11. init.py
Explanation:
The `__init__.py` file is used to mark a directory as a Python package. Without it, Python will
not treat the directory as a package, and its modules will not be importable.
Theory Questions:
1. What is the role of `__init__.py`?
2. Can `__init__.py` be empty?
3. What happens if `__init__.py` is missing?
4. Can you have multiple `__init__.py` files in a project?
5. Where is `__init__.py` typically found?
Practical Questions:
1. Create a package using `__init__.py`.
2. Test importing a module from the package.
3. Remove `__init__.py` and observe the behavior.
4. Modify `__init__.py` to include initialization code.
5. Use `__init__.py` in a multi-level directory structure.
---
12. manage.py
Explanation:
`manage.py` is the command-line utility for administrative tasks in a Django project. It
allows you to manage the project through commands like `runserver`, `migrate`,
`makemigrations`, and more.
Theory Questions:
1. What is the purpose of `manage.py`?
2. How do you run the server using `manage.py`?
3. What does the `migrate` command do?
4. Can you add custom commands to `manage.py`?
5. What are some common `manage.py` commands?
Practical Questions:
1. Use `manage.py` to run the server.
2. Create a migration using `manage.py`.
3. Use `manage.py` to create a superuser.
4. Check available commands using `manage.py help`.
5. Run tests with `manage.py`.
---
13. project
Explanation:
A Django project is a collection of settings, configurations, and apps. It serves as the overall
container for your Django application.
Theory Questions:
1. What is a Django project?
2. How does a project differ from an app in Django?
3. How do you create a project in Django?
4. What files are created when a Django project is generated?
5. Can a project contain multiple apps?
Practical Questions:
1. Create a Django project using `django-admin startproject`.
2. Explore the directory structure of a Django project.
3. Configure settings in `settings.py`.
4. Create an app within the project.
5. Run the development server for the project.
---
14. app
Explanation:
An app in Django is a self-contained module that handles a specific functionality within the
project, such as a blog, a store, or a user authentication system.
Theory Questions:
1. What is an app in Django?
2. How is an app different from a project in Django?
3. How do you create an app in Django?
4. How do you add an app to a project?
5. Can you have multiple apps in a single Django project?
Practical Questions:
1. Create a new app in a Django project.
2. Add the app to the `INSTALLED_APPS` list in `settings.py`.
3. Create a model in the app.
4. Define a view and map it to a URL in the app.
5. Create a template within the app.
---
Theory Questions:
1. What does WSGI stand for?
2. What is the role of ASGI in Django?
3. Which is more suitable for real-time applications: ASGI or WSGI?
4. How does Django use WSGI?
5. What is the main difference between WSGI and ASGI?
Practical Questions:
1. Check the `wsgi.py` file in a Django project.
2. Explore `asgi.py` in Django.
3. Set up Django for asynchronous support.
4. Run Django with an ASGI server.
5. Test synchronous and asynchronous views in Django.
---
16. Asynchronous, concurrency
Explanation:
Asynchronous programming allows Django to handle multiple requests at once without
blocking. This improves performance, especially in I/O-bound tasks like API calls or
database queries.
Theory Questions:
1. What is asynchronous programming?
2. How does asynchronous programming differ from synchronous?
3. When should you use asynchronous views in Django?
4. What libraries enable asynchronous support in Django?
5. What does concurrency mean in web development?
Practical Questions:
1. Write an asynchronous view in Django.
2. Test the behavior of synchronous and asynchronous views.
3. Use `async` and `await` in Django views.
4. Use `asyncio` for concurrent tasks in Django.
5. Measure performance between synchronous and asynchronous views.
---
17. settings.py
Explanation:
`settings.py` contains all the configuration settings for a Django project, including database
settings, static files settings, security options, and more.
Theory Questions:
1. What is the role of `settings.py` in a Django project?
2. Where do you configure the database in `settings.py`?
3. What is `ALLOWED_HOSTS` used for?
4. How do you add static files in `settings.py`?
5. What is the importance of `SECRET_KEY` in `settings.py`?
Practical Questions:
1. Configure the database in `settings.py`.
2. Set up static files and media directories.
3. Modify `ALLOWED_HOSTS` for production.
4. Change the `SECRET_KEY` for security.
5. Configure logging in `settings.py`.
---
18. urls & urlpatterns
Explanation:
`urls.py` defines the URL patterns that map to Django views. `urlpatterns` is a list of these
mappings.
Theory Questions:
1. What is the purpose of `urls.py` in a Django project?
2. How does Django match URLs to views?
3. What is the role of `urlpatterns`?
4. Can you use regular expressions in `urls.py`?
5. How do you include other URL configurations in Django?
Practical Questions:
1. Define a URL pattern for a view.
2. Include app URLs in the main `urls.py`.
3. Create dynamic URLs with parameters.
4. Use named URLs in Django templates.
5. Add an additional URL configuration for a new app.
---
Theory Questions:
1. What is middleware in Django?
2. Name some default middleware in Django.
3. How can you add custom middleware in Django?
4. What does `AuthenticationMiddleware` do?
5. Why is middleware important for security?
Practical Questions:
1. Add custom middleware to a Django project.
2. Modify request data in middleware.
3. Handle exceptions using middleware.
4. Check the effect of middleware on responses.
5. Disable default middleware temporarily.
---
20. Settings.py Variables
Explanation:
`settings.py` contains many important variables for configuring a Django project, such as
`INSTALLED_APPS`, `MIDDLEWARE`, and `DATABASES`.
Theory Questions:
1. What is `INSTALLED_APPS` in `settings.py`?
2. What is `DATABASES` used for in `settings.py`?
3. What is the difference between `DEBUG` and `ALLOWED_HOSTS`?
4. What does `MIDDLEWARE` do in `settings.py`?
5. How do you configure email settings in `settings.py`?
Practical Questions:
1. Modify `INSTALLED_APPS` to add a new app.
2. Set up database settings in `settings.py`.
3. Change `DEBUG` and test the application.
4. Add email configuration for sending notifications.
5. Create custom settings variables for your project.
---
Theory Questions:
1. What is CSRF in web applications?
2. How does CSRF protection work in Django?
3. Why is it important to use CSRF tokens?
4. How do you disable CSRF protection in Django?
5. Where are CSRF tokens used in forms?
Practical Questions:
1. Include CSRF tokens in a form in Django.
2. Enable and disable CSRF protection in Django.
3. Test CSRF attacks using Postman.
4. Check the CSRF token in the browser using developer tools.
5. Create a view that requires CSRF protection.
---
(And more topics will continue in the next part for Day 2 and Day 3)