Welcome to the Interneers Lab 2026 Python backend! This serves as a minimal starter kit for learning and experimenting with:
- Django (Python)
- MongoDB (via Docker Compose)
- Development environment in VSCode (recommended)
Important: Use the same email you shared during onboarding when configuring Git and related tools. That ensures consistency across all internal systems.
- Prerequisites & Tooling
- Setting Up the Project
- Running Services
- Verification of Installation
- Development Workflow
- Making Your First Change
- Running Tests (Optional)
- Hot Reloading
- MongoDB Connection
- Further Reading
- Important Note on settings.py
These are the essential tools you need:
-
Homebrew (macOS Only)
Why?
Homebrew is a popular package manager for macOS, making it easy to install and update software (like Python, Docker, etc.).
Install:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" -
Python 3.14 (3.12 or higher required)
Why 3.14?
This is the recommended version for the module's Python-related tasks, ensuring consistency across projects.
Install or Upgrade:
- macOS (with Homebrew):
brew install pythonor use pyenv:brew install pyenv brew update && brew upgrade pyenv pyenv install 3.14.3 - Windows: Download from python.org (ensure it's 3.14)
- Linux: Use your distro's package manager or pyenv
Verify:
python3 --version
You should see something like
Python 3.14.x.If you are getting an older version, you can either:
- Use the full path:
~/.pyenv/versions/3.14.3/bin/python - Or update your
.bashrc/.zshrc:vim ~/.zshrc # or any preferred editor of your choice alias python3="/path/to/python3.14" source ~/.zshrc # or ~/.bashrc
- macOS (with Homebrew):
-
virtualenv or built-in
venvWhy?
A virtual environment keeps project dependencies isolated from your system Python.
Install
pip3 install virtualenv(if needed)- or use
python3 -m venv venv
Verify
-
Try to activate the venv using the following command:
source venv/bin/activate # macOS/Linux .\venv\Scripts\activate # Windows
-
In most machines, your terminal prompt will be prefixed with something like
(venv).
Check which Python is being used:
-
macOS/Linux:
which python
This should return a path inside the
venv/directory (e.g.,.../backend/python/venv/bin/python) -
Windows:
where pythonThis should return a path inside
venv\Scripts\python.exe.
-
Docker & Docker Compose
Why?
We use Docker to run MongoDB (and potentially other services) in containers, preventing "works on my machine" issues.
Install
Verify
Verify version and successful installation with
docker --versionanddocker compose version. -
API & MongoDB Tools
- Postman, Insomnia, or Paw (only for mac) for API testing
- MongoDB Compass or a VSCode MongoDB extension
The python virtual env should be created inside the backend/python directory. Run the following commands:
cd backend/python
python3 -m venv venvTo activate the virtual environment:
# macOS/Linux
source venv/bin/activate# on Windows Powershell:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
.\venv\Scripts\activatepip install --upgrade pip
pip3 install -r requirements.txtBy default, requirements.txt includes:
- Django 6.0.2
- pymongo 4.16.0 (MongoDB driver)
Check your .gitignore
Make sure venv/ and other temporary files aren't committed.
Navigate to the backend/python directory:
cd backend/pythonStart the Django server on port 8001:
python manage.py runserver 8001Open http://127.0.0.1:8001/hello/ to see the "Hello World" endpoint.
Inside backend/python, you'll find a docker-compose.yaml.
To start MongoDB via Docker Compose:
docker compose up -dVerify with:
docker compose psMongoDB is now running on localhost:27019. Connect using root / example or update credentials as needed.
- Python:
python3 --version(should be 3.12+) - Django:
python -c "import django; print(django.get_version())"(should be 6.0.2) - Docker:
docker --version - Docker Compose:
docker compose version
Confirm that all meet the minimum version requirements.
-
Python (Microsoft) Provides language server support, debugging, linting, and IntelliSense for Python code.
-
Django (optional but helpful) Offers syntax highlighting and code snippets tailored for Django projects.
-
Docker Allows you to visualize, manage, and interact with Docker containers and images directly in VSCode.
-
(Optional) MongoDB for VSCode Lets you connect to and browse your MongoDB databases, run queries, and view results without leaving VSCode.
- Edit the
hello_worldfunction indjango_app/urls.py. - Refresh your browser at http://127.0.0.1:8001/hello/.
This section explains how to create a Django endpoint that reads a name parameter from the query string (e.g., /?name=Bob).
Open django_app/urls.py. Below, we'll define a function that looks for a name query parameter in request.GET:
# django_app/urls.py
from django.contrib import admin
from django.urls import path
from django.http import JsonResponse
def hello_name(request):
"""
A simple view that returns 'Hello, {name}' in JSON format.
Uses a query parameter named 'name'.
"""
# Get 'name' from the query string, default to 'World' if missing
name = request.GET.get("name", "World")
return JsonResponse({"message": f"Hello, {name}!"})
urlpatterns = [
path('admin/', admin.site.urls),
path('hello/', hello_name),
# Example usage: /hello/?name=Bob
# returns {"message": "Hello, Bob!"}
]Activate your virtual environment (if not already active):
source venv/bin/activate # macOS/Linux
.\venv\Scripts\activate # WindowsInstall dependencies (if you haven't):
cd backend/python # if you are not inside backend/python already.
pip3 install -r requirements.txtStart the server on port 8001:
python manage.py runserver 8001You should see:
Starting development server at http://127.0.0.1:8001/
Install a REST client like Postman (if you haven't already).
Create a new GET request.
Enter the endpoint, for example:
http://127.0.0.1:8001/hello/?name=Bob
Send the request. You should see a JSON response:
{
"message": "Hello, Bob!"
}- Stage and commit:
git add . git commit -m "Your descriptive commit message"
- Push to your forked repo (main branch by default):
git push origin main
cd backend/python
python manage.py testdocker compose psNote: This command displays the status of the containers, including whether they are running, their assigned ports, and their names, as defined in the docker-compose.yaml file. If you have set up a MongoDB server using Docker and connected it to your Django application, you can use this command to verify that the MongoDB container is running properly.
Django's development server supports hot reloading out of the box. When you modify any Python file, the server automatically detects the change and restarts. Simply save your file and refresh the browser to see your changes.
MongoDB connections differ depending on your setup:
When running the project locally, MongoDB is exposed on port 27019:
mongodb://root:example@localhost:27019/?authSource=admin
To ensure flexibility across environments, use environment variables for the MongoDB connection. For example:
# Database
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases
from dotenv import load_dotenv
import os
from pymongo import MongoClient
load_dotenv()
MONGO_USER = os.getenv("MONGO_USER", "root")
MONGO_PASS = os.getenv("MONGO_PASS", "example")
MONGO_PORT = os.getenv("MONGO_PORT", "27019")
MONGO_HOST = os.getenv("MONGO_HOST", "localhost")
client = MongoClient(
f"mongodb://{MONGO_USER}:{MONGO_PASS}@{MONGO_HOST}:{MONGO_PORT}/?authSource=admin"
)
DATABASES = {}- Django: https://docs.djangoproject.com/en/6.0/
- MongoDB: https://docs.mongodb.com/
- Docker Compose: https://docs.docker.com/compose/
- pymongo: https://pymongo.readthedocs.io/en/stable/
- You should commit
settings.pyso the Django configuration is shared. - However, never commit secrets (API keys, passwords) directly. Use environment variables or
.envfiles (excluded via.gitignore).
# Virtual environment
python3 -m venv venv # Create virtual environment
source venv/bin/activate # Activate (macOS/Linux)
.\venv\Scripts\activate # Activate (Windows)
deactivate # Deactivate
# Dependencies
pip install -r requirements.txt # Install dependencies
pip freeze > requirements.txt # Update requirements file
# Django
python manage.py runserver 8001 # Start dev server on port 8001
python manage.py test # Run tests
# Docker / MongoDB
docker compose up -d # Start MongoDB
docker compose down # Stop MongoDB
docker compose ps # List running containers
docker compose logs -f # View logs