Creating a New Django Project

Learn to bootstrap a new Django project.

In Django, a project is an umbrella that envelops each application. For example, we can have an e-commerce Django project within which there are several applications, such as payment, order, shipping, cart, and so on. The benefit of this approach is that we can reuse each Django application inside another Django project.

When we initialize a new Django project, Django provides us with some basic files to help us get started quickly.

Install Django

To install Django, we can use the pip command. This is the package manager for Python:

pip install django

This command installs the latest version of Django.

Create a new project

Once Django is installed, we can create a new project using the following command.

django-admin startproject tdd_django .

This creates a Django project named tdd_django. Let’s go over the basic files that Django gives us by default when we create a new Django project:

/
└───tdd_django
    │   __init__.py
    │   asgi.py
    │   settings.py
    │   urls.py
    │   wsgi.py
    manage.py

  • The manage.py file runs Django management commands that create a new application, migrate the database, run tests, and so on.
  • The settings.py file contains the settings Django has already configured for us.
  • The urls.py files are where the project URLs reside.

Create a new application

We’ll create a new Django application called elibrary_app. Recall that we’re building an e-library application as the project for this course:

python manage.py startapp elibrary_app

After creating this application, we get a test.py file inside the folder. This is the file where all our tests classes and methods will reside.

We also need to add this application as a part of the INSTALLED_APPS for this project. This allows Django to be aware of the application. This can be found in the settings.py file under the tdd_django project.

INSTALLED_APPS = [
    ...

    'elibrary_app.apps.ElibraryAppConfig',
]

Example

Click the “Run” button. You should see the default Django home page in the browser as the output:

Get hands-on with 1200+ tech skills courses.