Lesson 9 of 60 – Create Django Project
15%

🚀 Create Django Project

In this lesson, you will learn how to create your first Django project. A Django project contains the main configuration and components required to build a web application.

Note: Before creating a project, make sure Python and Django are installed and your virtual environment is activated.

1. What Is a Django Project?

A Django project is a collection of configuration files and applications that work together to build a web application.

The project contains important settings such as URLs, installed apps, database configuration and other project-level options.

2. Prepare the Environment

Before creating a project, open your terminal and make sure the correct virtual environment is active.

For example:

venv\Scripts\activate

3. Check Django Installation

Verify that Django is available before creating the project.

python -m django --version

If a version number is displayed, Django is available in the current Python environment.

4. Create a Project Using django-admin

Django provides the django-admin command for creating projects.

django-admin startproject myproject

This command creates a new Django project named myproject.

5. Understand startproject

The command contains two important parts:

django-admin startproject myproject
  • django-admin – Django command-line utility
  • startproject – command for creating a project
  • myproject – name of the project

6. Create a Project Using Python

You can also create a Django project using Python's module execution syntax.

python -m django startproject myproject

This is useful because it explicitly runs Django using the current Python environment.

7. Choose a Project Name

You can choose a meaningful name for your project.

For example:

django-admin startproject schoolproject

The project name should be a valid Python package name.

8. Project Directory

It is common to create the project inside a dedicated directory.

mkdir MyDjangoProject
cd MyDjangoProject
django-admin startproject myproject

Django will create the project structure inside the current directory.

9. Default Project Structure

After creating the project, you will see a structure similar to:

myproject/
    manage.py
    myproject/
        __init__.py
        settings.py
        urls.py
        asgi.py
        wsgi.py

10. The manage.py File

manage.py is a command-line utility created automatically when you create a Django project.

It is commonly used to run development commands for your project.

11. The settings.py File

The settings.py file contains project configuration.

It can contain settings for databases, installed applications, middleware, templates, static files and other Django options.

12. The urls.py File

The urls.py file is used to define URL patterns for the project.

It helps Django determine which view should handle a particular URL.

13. The __init__.py File

The __init__.py file marks the project directory as a Python package.

It is created automatically as part of the project structure.

14. The asgi.py File

asgi.py provides an entry point for servers supporting ASGI applications.

It is useful when deploying Django applications in environments that support asynchronous server interfaces.

15. The wsgi.py File

wsgi.py provides an entry point for WSGI-compatible servers.

It is commonly relevant when deploying Django applications with traditional synchronous web server setups.

16. Run the Django Development Server

After creating the project, you can start Django's development server using:

python manage.py runserver

Django will start a local development server.

17. Open the Local Website

After starting the development server, open the local server address shown in the terminal.

Typically, Django uses:

http://127.0.0.1:8000/

You can open this address in a web browser.

18. Stop the Development Server

To stop the development server, return to the terminal and press:

Ctrl + C

This stops the running development server.

19. Runserver from the Project Directory

Run manage.py commands from the directory containing manage.py.

python manage.py runserver

This makes it easier for Django to locate the project's configuration.

20. Create Project in the Current Directory

Django can also create the project files directly in the current directory by using a dot:

django-admin startproject myproject .

The dot represents the current directory.

21. Difference Between the Two Commands

Command Result
django-admin startproject myproject Creates a project directory named myproject
django-admin startproject myproject . Creates project files in the current directory

22. Avoid Unnecessary Nested Folders

When creating a project, understand where you are running the command. Using the dot syntax can be useful when you already have a dedicated project directory.

For example:

mkdir MyDjangoProject
cd MyDjangoProject
django-admin startproject myproject .

23. Check the Project Files

After creating the project, check that the important files are present.

  • manage.py
  • settings.py
  • urls.py
  • asgi.py
  • wsgi.py
  • __init__.py

24. Create Project with a Different Name

Project names can be customized according to the application.

For example:

django-admin startproject studentportal

This creates a Django project named studentportal.

25. Project Name and Application Name

A Django project and a Django app are different concepts.

The project contains overall configuration, while apps are used to organize specific functionality.

Apps will be covered in later lessons.

26. Common Project Creation Mistake

A common mistake is running the command from an unexpected directory.

Before creating a project, use cd to move to the directory where you want your Django project to be created.

27. Complete Windows Example

mkdir MyDjangoProject
cd MyDjangoProject
python -m venv venv
venv\Scripts\activate
python -m pip install Django
django-admin startproject myproject .
python manage.py runserver

This creates a project directory, prepares a virtual environment, installs Django, creates the project and starts the development server.

28. Complete Linux/macOS Example

mkdir MyDjangoProject
cd MyDjangoProject
python3 -m venv venv
source venv/bin/activate
python -m pip install Django
django-admin startproject myproject .
python manage.py runserver

29. Your First Django Project

After successfully running the startproject command, you have created the basic structure of your first Django project.

The next step is to understand what each project file and folder does.

30. Create Django Project Summary

The main command for creating a Django project is:

django-admin startproject myproject

You can also create the project in the current directory:

django-admin startproject myproject .

After creation, use manage.py to run Django commands such as:

python manage.py runserver

You now have the basic structure required to start building a Django application.

📌 Key Points

  • A Django project contains the main configuration of a web application.
  • django-admin startproject creates a Django project.
  • manage.py is used to run project management commands.
  • settings.py contains project configuration.
  • urls.py contains URL configuration.
  • asgi.py and wsgi.py provide server entry points.
  • django-admin startproject myproject . creates the project in the current directory.

🧠 Quick Quiz

Question: Which command is used to create a new Django project?