Skip to main content
Django Basics Tutorial
CHAPTER 04 Beginner

Creating Your First Django Project

Updated: May 14, 2026
25 min read

# CHAPTER 4

Creating Your First Django Project

1. Introduction

With Python installed and our architectural blueprint understood, it is time to generate the actual code. Django provides a powerful command-line utility called django-admin that automatically scaffolds the entire folder structure for a professional web application. In this chapter, we will generate a new project, explore the critical configuration files, and launch the built-in development server.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Use django-admin to scaffold a new Django project.
  • Understand the purpose of manage.py and settings.py.
  • Start the Django development server.
  • Access the default Django welcome page in a web browser.

3. Beginner-Friendly Explanation

Imagine you are starting a new company. You don't want to build the office building brick by brick. You hire a construction company (django-admin) to instantly build the office for you. They hand you the keys to the building. Inside, there is a master control room (manage.py) where you can turn the power on, run security checks, and update the database. There is also a rulebook (settings.py) that tells the office what language to speak, what timezone to use, and where the security cameras are located. You now have a fully functional office, ready for employees!

4. Step 1: Creating the Project

Ensure your terminal is open, and your virtual environment is active (you should see (env) in your terminal prompt).

Run the following command to tell Django to build your project. We will call our project core:

bash
1
django-admin startproject core .

*(CRITICAL: Notice the space and the period . at the very end of the command! The period tells Django to build the files in your CURRENT folder, rather than creating an annoying nested folder structure).*

5. Step 2: Exploring the Generated Files

Type ls (Mac/Linux) or dir (Windows) in your terminal. You will see a new file and a new folder:
text
123456789
/my_django_learning
    env/              (Your virtual environment)
    manage.py         (The Master Control Room)
    core/             (The Project Configuration Folder)
        __init__.py
        settings.py   (The Rulebook)
        urls.py       (The Traffic Director)
        asgi.py
        wsgi.py

Key Files Explained:

  • manage.py: A command-line utility that lets you interact with this Django project. You will use it constantly to start the server and update the database.
  • settings.py: Contains all the configuration for your Django installation (database connection, installed plugins, security keys, timezones).
  • urls.py: The main table of contents for your site. It routes URLs to specific views.

6. Step 3: Running the Development Server

Django comes with a built-in, lightweight web server so you can test your code locally without installing complex software like Apache or Nginx.

In your terminal, run the master control file:

bash
1
python manage.py runserver

You should see output similar to this:

text
1234567
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
October 12, 2026 - 14:05:00
Django version 5.0, using settings 'core.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

7. Step 4: Viewing Your Project

Open Google Chrome or Firefox. In the address bar, type: http://127.0.0.1:8000/ (or http://localhost:8000/).

You will see the iconic Django rocket ship taking off with the text: "The install worked successfully! Congratulations!"

*Note: You may see a red warning in your terminal about "unapplied migrations." Ignore this for now; we will solve it when we learn about databases in Chapter 8.*

8. Backend Workflow: Stopping and Restarting

The terminal window running your server is now "locked." You cannot type new commands into it. The server is actively listening for internet traffic.
  • To stop the server and regain control of your terminal, press Ctrl + C.
  • Whenever you save a Python file, the development server will automatically restart itself to apply the new changes. (If you change HTML templates, you just refresh your browser).

9. Best Practices

  • The Secret Key: If you open core/settings.py, you will see a massive string of random characters called SECRET_KEY. This key is used to encrypt passwords and sessions. Never share this key. In production, this key must be hidden inside a .env file, just like database passwords.

10. Common Mistakes

  • Forgetting the Period: If you run django-admin startproject core (without the period at the end), Django creates a folder named core, and *inside* that folder, it creates another folder named core. This nested core/core/settings.py structure confuses beginners endlessly when trying to import files. Always use the period!

11. Exercises

  1. 1. Open core/settings.py. Locate the TIME_ZONE variable. Change it from 'UTC' to your local timezone (e.g., 'America/New_York' or 'Asia/Kolkata'). Save the file.

12. Coding Challenges

  • Challenge: Open your terminal, stop the server with Ctrl + C. Then, use manage.py to start the server again, but this time, force it to run on port 8080 instead of the default 8000. (Hint: Search online for "django runserver specific port").

13. MCQs with Answers

Question 1

Which command is used to initially generate the core configuration files for a new Django project?

Question 2

Which generated file acts as the primary command-line utility to interact with your specific Django project, allowing you to start the server and run database migrations?

14. Interview Questions

  • Q: Explain the purpose of the settings.py file in a Django project. Name at least three critical configurations that are managed within this file.
  • Q: What is the built-in Django development server? Why should it NEVER be used in a live production environment?

15. FAQs

Q: Can I rename manage.py? A: You technically could, but you shouldn't. It breaks conventions, and every Django tutorial on the internet assumes your file is named manage.py.

16. Summary

In Chapter 4, we transitioned from theory to practice. We utilized the django-admin command to scaffold a robust, professional project structure instantly. We explored the critical role of manage.py as our master control tool, and settings.py as our global configuration rulebook. Finally, we successfully launched the built-in development server and viewed our live application in the browser.

17. Next Chapter Recommendation

Our project is created, but it is currently empty. To add features like a blog or a store, we must create "Apps". Proceed to Chapter 5: Django Apps and Project Structure.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·