Bird
Raised Fist0
Djangoframework~10 mins

Django project structure walkthrough - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Django project structure walkthrough
Start: django-admin startproject
↓
Create project folder
↓
Create manage.py file
↓
Create inner project folder
↓
Create __init__.py
↓
Create settings.py
↓
Create urls.py
↓
Create asgi.py & wsgi.py
↓
Project ready for apps & runserver
This flow shows how Django creates the main project structure step-by-step when you start a new project.
Execution Sample
Django
django-admin startproject mysite
cd mysite
ls
Creates a new Django project folder named 'mysite' with the default files and folders inside.
Execution Table
StepActionCreated ItemDescription
1Run django-admin startproject mysitemysite/Main project folder created
2Inside mysite/, create manage.pymanage.pyCommand-line utility for project management
3Create inner mysite/ foldermysite/mysite/Contains project settings and config
4Create __init__.py inside inner mysite/__init__.pyMarks folder as Python package
5Create settings.py inside inner mysite/settings.pyProject configuration settings
6Create urls.py inside inner mysite/urls.pyURL routing for the project
7Create asgi.py and wsgi.py inside inner mysite/asgi.py, wsgi.pyEntry points for web servers
8Project structure readyAll files/foldersReady to add apps and run server
💡 All default files and folders created, project structure complete.
Variable Tracker
ItemBefore startprojectAfter step 1After step 2After step 3After step 7Final
mysite folderDoes not existExistsExistsExistsExistsExists
manage.pyDoes not existDoes not existExistsExistsExistsExists
mysite inner folderDoes not existDoes not existDoes not existExistsExistsExists
__init__.pyDoes not existDoes not existDoes not existExistsExistsExists
settings.pyDoes not existDoes not existDoes not existExistsExistsExists
urls.pyDoes not existDoes not existDoes not existExistsExistsExists
asgi.py & wsgi.pyDoes not existDoes not existDoes not existExistsExistsExists
Key Moments - 3 Insights
Why are there two folders named 'mysite' after creating the project?
The outer 'mysite' is the project container folder. The inner 'mysite' is a Python package holding settings and config files, as shown in steps 1 and 3 of the execution_table.
What is the purpose of manage.py?
manage.py is a command-line tool to interact with the project, like running the server or migrations. It is created in step 2 and is outside the inner project folder.
Why do we have __init__.py inside the inner folder?
__init__.py marks the inner folder as a Python package so Python can import settings and other modules. This is shown in step 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what file is created at step 5?
Asettings.py
Bmanage.py
Curls.py
D__init__.py
💡 Hint
Check the 'Created Item' column for step 5 in the execution_table.
At which step does the inner 'mysite' folder get created?
AStep 6
BStep 2
CStep 3
DStep 1
💡 Hint
Look for 'Create inner mysite/ folder' in the 'Action' column of the execution_table.
If manage.py was missing, which step likely failed?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
manage.py is created in step 2 according to the execution_table.
Concept Snapshot
Django project structure:
- Outer folder: project container
- manage.py: command tool
- Inner folder: Python package
- settings.py: config
- urls.py: routing
- asgi.py/wsgi.py: server entry
Created by django-admin startproject
Full Transcript
When you run 'django-admin startproject mysite', Django creates a main folder named 'mysite'. Inside it, there is a manage.py file for commands. Also, an inner folder named 'mysite' is created, which is a Python package containing __init__.py, settings.py, urls.py, asgi.py, and wsgi.py. These files configure the project, handle URL routing, and provide server interfaces. This structure is ready for adding apps and running the development server.

Practice

(1/5)
1. Which file in a Django project is used to run commands like starting the server or creating migrations?
easy
A. manage.py
B. settings.py
C. urls.py
D. wsgi.py

Solution

  1. Step 1: Identify the command runner file

    The manage.py file is designed to run commands like starting the server or making migrations.
  2. Step 2: Understand other files' roles

    settings.py holds configuration, urls.py routes URLs, and wsgi.py is for deployment interface.
  3. Final Answer:

    manage.py -> Option A
  4. Quick Check:

    Command runner = manage.py [OK]
Hint: Remember: manage.py runs commands for your project [OK]
Common Mistakes:
  • Confusing settings.py as command runner
  • Thinking urls.py runs commands
  • Assuming wsgi.py runs server commands
2. Which folder typically contains the settings and URL configuration files in a Django project?
easy
A. The app folder
B. The templates folder
C. The project folder
D. The static folder

Solution

  1. Step 1: Identify where settings.py and urls.py live

    These files are inside the main project folder, which shares the project name.
  2. Step 2: Differentiate folders

    App folders contain app-specific code, templates hold HTML files, static holds CSS/JS/images.
  3. Final Answer:

    The project folder -> Option C
  4. Quick Check:

    Settings and URLs = project folder [OK]
Hint: Settings and URLs live in the project folder, not apps [OK]
Common Mistakes:
  • Thinking settings.py is inside an app folder
  • Confusing templates folder with project folder
  • Assuming static folder holds config files
3. Given this Django project structure snippet:
myproject/
  manage.py
  myproject/
    settings.py
    urls.py
  blog/
    models.py
    views.py
    urls.py

Which file would you edit to add a new URL route for the blog app?
medium
A. myproject/settings.py
B. blog/urls.py
C. myproject/urls.py
D. manage.py

Solution

  1. Step 1: Understand URL routing in Django

    The main project urls.py includes app URLs, but app-specific routes go in the app's urls.py.
  2. Step 2: Locate where to add blog routes

    To add blog-specific URLs, edit blog/urls.py where blog views are connected to paths.
  3. Final Answer:

    blog/urls.py -> Option B
  4. Quick Check:

    App URLs go in app's urls.py [OK]
Hint: Add app URLs inside the app's own urls.py file [OK]
Common Mistakes:
  • Adding app URLs directly in project urls.py
  • Editing settings.py for URL routes
  • Trying to add routes in manage.py
4. You try to run your Django project but get an error: ModuleNotFoundError: No module named 'blog'. Which of these is the most likely cause?
medium
A. You forgot to import models.py in views.py
B. You did not create a urls.py file in the blog app
C. You ran manage.py from the wrong folder
D. You forgot to add the blog app to INSTALLED_APPS in settings.py

Solution

  1. Step 1: Understand the error meaning

    The error means Python cannot find the blog app module when loading the project.
  2. Step 2: Check common causes

    Not adding the app name to INSTALLED_APPS in settings.py causes this error because Django doesn't recognize the app.
  3. Final Answer:

    Forgot to add blog to INSTALLED_APPS -> Option D
  4. Quick Check:

    Missing app in INSTALLED_APPS = ModuleNotFoundError [OK]
Hint: Always add new apps to INSTALLED_APPS in settings.py [OK]
Common Mistakes:
  • Assuming missing urls.py causes ModuleNotFoundError
  • Running manage.py from wrong folder usually gives different error
  • Forgetting imports in views.py causes different errors
5. You want to create a new Django app called shop inside your project. Which sequence of actions correctly follows Django project structure best practices?
hard
A. Run python manage.py startapp shop, then add shop to INSTALLED_APPS in settings.py
B. Create a folder named shop manually, then add shop to urls.py
C. Add shop to INSTALLED_APPS first, then run python manage.py startapp shop
D. Run python manage.py startproject shop inside your project folder

Solution

  1. Step 1: Create the app properly

    Use python manage.py startapp shop to create the app folder with correct files.
  2. Step 2: Register the app in settings

    Add shop to INSTALLED_APPS in settings.py so Django knows about it.
  3. Final Answer:

    Run startapp then add to INSTALLED_APPS -> Option A
  4. Quick Check:

    Start app then register in settings [OK]
Hint: Always start app with manage.py then add to INSTALLED_APPS [OK]
Common Mistakes:
  • Manually creating app folder misses essential files
  • Adding app to INSTALLED_APPS before creating it
  • Using startproject instead of startapp for apps
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard