Creating and running a Django project
Now that we have Django installed, we are ready to create our Django project.
There are several ways to create Django projects. In this book, we will use django-admin
. django-admin is Django’s command-line utility for administrative tasks. It provides various commands to help you create, manage, and interact with Django projects, applications, and other related components.
In the Terminal, navigate to the folder where you want to create your project and run the following command:
django-admin startproject moviesstore
This will create a moviesstore
folder in your current directory. This folder contains our Django application code. We will discuss its contents later. For now, let’s run our first website on the Django local web server.
In the Terminal, run the cd
command to move into the created folder:
cd moviesstore
Then, run the following command:
- For macOS, run this:
python3 manage.py runserver
- For Windows, run this:
python manage.py runserver
When you run the aforementioned commands, you start the local web server on your machine (for local development purposes). There will be a URL link – http://127.0.0.1:8000/
(equivalent to http://localhost:8000
). Open this link in a browser, and you will see the default landing page, as shown in Figure 1.5:
Figure 1.5 – The landing page of the Django project
This means that your local web server is running and serving the landing page. Sometimes, you will need to stop the server in order to run other Python commands. To stop the local server, press Ctrl + C in the Terminal.
We executed our first Django project successfully. Now, it is time to introduce the application we will develop in this book.