Django projects are Python packages. You import apps with dotted paths, configure INSTALLED_APPS, and isolate dependencies in a virtual environment.
Imports in Django
from django.shortcuts import render, get_object_or_404
from blog.models import Article
Avoid circular imports—keep models lean, import views only where needed, use lazy references ("app.Model" strings) for ForeignKey when necessary.
Virtual environment workflow
python -m venv .venv- Activate:
source .venv/bin/activate(macOS/Linux) pip install djangodjango-admin startproject mysite
Commit requirements.txt; never commit the .venv folder itself.
Important interview questions and answers
- Q: What is
INSTALLED_APPS?
A: List of Django apps whose models, templates, and static files are loaded—includesdjango.contrib.admin, your apps, and third-party packages. - Q: requirements.txt vs Pipfile?
A: Both pin dependencies; teams pick one standard—reproducible installs matter more than the tool. - Q: Circular import fix?
A: Move shared code to a third module, use string model references, or import inside functions.
Self-check
- Why activate a venv before
pip install django? - What does
from blog.models import Articlerequire in settings?