Creating a Django project


Lesson 9 of 14 · Python for the web

In the previous lesson we met the Django framework and its role in developing web applications.

Now we will make our first Django project and start a local web server.

A Django project is the basic structure of a web application.

Creating a new project

A Django project is created with the command:


django-admin startproject myproject

This command creates a new folder with all the files a Django application needs.


The structure of a Django project

After the project is created we get this structure:


myproject/

manage.py

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

Each of these files has its own purpose.

  • manage.py – a tool for managing the project
  • settings.py – the project configuration
  • urls.py – defines the URL addresses
  • wsgi.py – runs the server
Most of the time programmers work with the files settings.py and urls.py.

Starting the Django server

Before we start the server, we have to go into the project folder:


cd myproject

Then we start the server with the command:


python manage.py runserver

If everything is set up correctly, Django starts a local web server.


Opening the application in the browser

Open the following address in the browser:


http://127.0.0.1:8000
The Django start page
The install worked successfully! Congratulations!

This page confirms that the Django server is running.


What does manage.py do?

The file manage.py is used to manage a Django project.

With it we can:

  • start the server
  • create applications
  • work with the database
  • run migrations

Mini project – Starting the server

Create a new Django project and start the server.


django-admin startproject myproject

cd myproject

python manage.py runserver

The goal of this project

  • create a Django project
  • start a local server
  • open the Django page in the browser

Related lessons


Frequently asked questions

What is a Django project?

A Django project is the basic structure of a web application.

Which port does the Django server use?

The default port is 8000.

What does manage.py do?

Manage.py is a tool for managing a Django project.

Can a project have several applications?

Yes. A Django project can contain several applications.