No module named django
Likely cause: The selected Python does not have Django installed.
Check and correct: Activate the environment and run python -m pip install -r requirements.txt. Compare python -m pip --version with the environment path.
PROJECT 1 · LESSON 1 OF 16
Build a local Python environment and trace your first browser request.
Start a new practice folder. The completed checkpoint includes all configuration and source files.
Extract the ZIP and open the folder containing manage.py. Create a Python virtual environment, install requirements.txt and run migrate. Read README.md for checkpoint-specific commands and LESSON.md for offline explanations. Checkpoints contain no database records or private credentials.
A website begins with a request and a response. Before databases, shopping carts or login screens, prove that your Python program can receive a browser request and return something visible. This small result gives you a reliable starting point for every later project.
Use Python 3.12 or 3.13; these checkpoints were verified with Python 3.13 and Django 5.2.18 LTS. Know Python functions, lists, dictionaries and basic classes before starting. This course uses server-rendered HTML, not a JavaScript frontend.
Keep one practice folder named edushop outside the EduPoly website repository. Each checkpoint is cumulative. You can type the files or extract the completed checkpoint, but do not run startproject over an extracted project.
Python is the language that runs your application. Django is a Python framework that supplies URL matching, request objects, responses, templates, forms, database access and authentication. The browser does not run your Python. It sends an HTTP request to a server, and receives a response such as HTML. You can therefore build this course without React or a JavaScript build tool.
Know variables, dictionaries, lists, functions, imports, basic classes and indentation before starting. You do not need advanced Python, but you should be able to explain a function receiving an argument and returning a value. In our first view the argument is request and the return value is HttpResponse.
Install Python 3.12 or 3.13 from python.org and a code editor. On Windows, check Python installation with py --version; on macOS or Linux use python3 --version. If python3 is missing, install it before running the commands below. Do not name your own files django.py or typing.py because they would shadow installed modules.
A virtual environment is a folder containing an isolated Python environment. Create it with python3 -m venv .venv on macOS/Linux or py -m venv .venv on Windows. Activate with source .venv/bin/activate on macOS/Linux, or .venv\Scripts\Activate.ps1 in PowerShell. If activation is restricted, run .venv\Scripts\python.exe directly; no policy change is necessary. Once activated, python -m pip installs into this environment.
Use Django 5.2.18 for the course checkpoints. The 5.2 LTS series gives a consistent learning target; follow security updates before operating a real store. requirements.txt records the version so a second machine installs the same framework. A dependency file describes what to install; it does not contain the installed packages.
The outer edushop directory is your workspace. config is the Django project package: it connects settings and top-level URLs. shop is a Django app: a feature package that will grow into the storefront. One project can contain multiple apps, which is why tasks and orders join later. manage.py runs commands using this project’s settings.
Choose one starting method. To build from scratch, use the terminal scaffold commands and then replace the listed files. To use the completed download, extract it, open the directory containing manage.py, create a virtual environment there and install requirements.txt. Do not run startproject inside a completed checkpoint. After installation run python manage.py migrate, then python manage.py runserver and open http://127.0.0.1:8000/.
runserver is a development server. Keep that terminal open while browsing; Ctrl+C stops it. It reloads Python changes during development. A browser refresh sends a new request. Deployment later uses Gunicorn, a process manager supplied by hosting, PostgreSQL and production settings.
Read this sequence before the source. Identify the input, the component or function that handles it, and the result the learner sees.
The browser requests GET / from port 8000.
Django loads config.settings and its root URL configuration.
The empty path matches the home view in shop.
home receives an HttpRequest and returns HttpResponse.
The browser displays the response body; a refresh repeats the sequence.
# macOS / Linux — from a new working folder
python3 --version
mkdir edushop
cd edushop
python3 -m venv .venv
source .venv/bin/activate
# Windows PowerShell — use these instead of the activation commands above
# py -3 --version
# mkdir edushop
# cd edushop
# py -3 -m venv .venv
# .\.venv\Scripts\Activate.ps1
# If activation is blocked, invoke .\.venv\Scripts\python.exe directly.
# From scratch only: skip these three lines when using the ZIP
python -m pip install Django==5.2.18
python -m django startproject config .
python manage.py startapp shop
# After adding the lesson files (or extracting the checkpoint)
python -m pip install -r requirements.txt
python manage.py migrate
python manage.py runserverThe paths below are relative to your practice project. Each block is the complete file at this checkpoint. Read its responsibility first, type or copy the code, then use the walkthrough to explain the important statements.
Pin the teaching framework so all learners use the same API baseline.
Django==5.2.18
Run Django management commands with this project’s settings.
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
Mark config as a Python package.
Configure this Django project and register its applications.
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
# Local learning only. Project 8 replaces this with required production configuration.
SECRET_KEY = "development-only-edupoly-do-not-use-for-a-live-site"
DEBUG = True
ALLOWED_HOSTS = ["localhost", "127.0.0.1", "testserver"]
INSTALLED_APPS = [
"django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes",
"django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles",
'shop',
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = "config.urls"
TEMPLATES = [{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR / "templates"], "APP_DIRS": True,
"OPTIONS": {"context_processors": [
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
]},
}]
WSGI_APPLICATION = "config.wsgi.application"
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": BASE_DIR / "db.sqlite3"}}
AUTH_PASSWORD_VALIDATORS = [
{"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
]
LANGUAGE_CODE = "en-us"
TIME_ZONE = "Asia/Kolkata"
USE_I18N = True
USE_TZ = True
STATIC_URL = "/static/"
STATIC_ROOT = BASE_DIR / "staticfiles"
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
LOGIN_URL = "login"
LOGIN_REDIRECT_URL = "tasks:list"
LOGOUT_REDIRECT_URL = "shop:home"
Dispatch incoming paths to the correct application.
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path("admin/", admin.site.urls),
path("", include("shop.urls")),
]
Expose Django to a WSGI-compatible production server later.
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
application = get_wsgi_application()
Mark shop as the application package.
Map the empty remaining path to the home view.
from django.urls import path
from . import views
app_name = "shop"
urlpatterns = [path("", views.home, name="home")]
Return the first HTTP response.
from django.http import HttpResponse
def home(request):
return HttpResponse("<h1>Hello, Django!</h1><p>My first working website.</p>")
Exclude local environments, databases and generated assets from source control.
.venv/
__pycache__/
*.pyc
db.sqlite3
.env
staticfiles/
Change only the text returned by home. Predict whether a database migration is required.
The new text appears after reload and refresh; no migration is needed.
A response string is application behavior. Migrations change database structure, and this view does not query a model.
If importing Django fails, check which Python interpreter is active. Do not install globally to mask a virtual-environment mismatch.
Likely cause: The selected Python does not have Django installed.
Check and correct: Activate the environment and run python -m pip install -r requirements.txt. Compare python -m pip --version with the environment path.
Likely cause: The terminal is in the wrong directory.
Check and correct: Open the extracted edushop folder containing manage.py. Do not run project commands from its parent folder.
Add a second paragraph describing your future store.
Attempt these questions before opening the explanations. Use the source above to justify your answer.
Separate environments let two projects use different versions without replacing each other’s packages. The virtual environment stays local; requirements.txt travels with the source.
No. It is a Python package loaded by the same Django process. The app separates related features; config connects those features into one website.