Module 10 / Project 01 — Django Setup¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| — | This project | Walkthrough | — | Flashcards | — | — |
Focus¶
Creating a Django project from scratch: startproject, startapp, models, admin, migrations, and runserver.
Why this project exists¶
Every Django application starts the same way: you run startproject, then startapp, define models, create migrations, and start the development server. This project walks you through that process step by step. Instead of running Django commands blindly, you will use a guided setup script that creates the project structure and explains every generated file along the way.
Understanding the file structure Django creates is essential. Each file has a specific purpose, and knowing what goes where will save you hours of confusion later.
Run¶
The script creates a Django project and app, then prints an explanation of every file it generated. After running it, explore the created directory structure.
To verify the generated project works:
cd demo_project
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
Then open your browser to:
- http://127.0.0.1:8000 — Django welcome page
- http://127.0.0.1:8000/admin — Django admin interface (log in with the superuser you created)
Press Ctrl+C to stop the server.
Expected output¶
Running setup_guide.py prints explanations like:
=== Django Project Setup Guide ===
[1/6] Creating project directory: demo_project/
Created: demo_project/manage.py
-> The command-line entry point for your Django project.
Run migrations, start the server, create apps — all through manage.py.
Created: demo_project/demo_project/settings.py
-> The central configuration file. Database settings, installed apps,
middleware, templates, and more are all configured here.
...
Running python manage.py migrate applies Django's built-in database tables:
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
...
Alter it¶
- Open
setup_guide.pyand add a new model field to theItemmodel (e.g.,description = models.TextField(blank=True)). Re-run the script and verify the field appears. - Add a second model called
Categorywith anamefield. Add aForeignKeyfromItemtoCategory. - Modify the script to also generate an
admin.pythat registers both models.
Break it¶
- In the generated
settings.py, remove'django.contrib.admin'fromINSTALLED_APPS. Try visiting/admin. What happens? - In the generated model, change
models.CharField(max_length=200)tomodels.CharField()(remove max_length). Try runningmakemigrations. What error do you get? - Delete the generated
migrations/directory and try runningmigrate. What happens?
Fix it¶
- Add
'django.contrib.admin'back toINSTALLED_APPS. The admin interface requires this app. - Add
max_length=200back.CharFieldrequires amax_lengthargument. If you want unlimited text, useTextFieldinstead. - Run
makemigrationsfirst to regenerate the migration files, thenmigrate. Django needs migration files to know what database changes to make.
Explain it¶
- What is the difference between a Django "project" and a Django "app"? Why does Django separate them?
- What does
manage.pydo? How is it different fromdjango-admin? - What are migrations? Why doesn't Django just read your models and create tables directly?
- What does
INSTALLED_APPScontrol? What happens if you define a model in an app that is not listed there?
Mastery check¶
You can move on when you can:
- explain every file in a new Django project without looking at the guide,
- create a model, make migrations, and apply them from memory,
- access the admin interface and add/edit objects,
- describe what
settings.pycontrols and find any setting by name.
Related Concepts¶
Next¶
Continue to 02-views-templates.