Django is a Python framework for web development. It builds the application structure and integrates various templates,
To use Django, we have to install Python in our system. Once we have the Python installed in our system, we must install Django using the PIP—a package manager for Python packages or modules.
Now that we have the Django installed in our system, we can execute the following command to create a Django project.
django-admin startproject educative_site
We can execute the following command to get the file structure of the Django's project we have created recently.
ls -R educative_site/
The details of the created project structure are given below:
educative_site__init__.py # empty file that tells interpreter that the folder is a packageasgi.py # files that are used by asgi compatible servers to host project after developmentsettings.py # contains the configuraions about the particular project; Templates,Debug Mode, and Databse declarationurls.py # contains the url to every endpoint on the projectwsgi.py # files that are used by wsgi compatible servers to host project after developmentmanage.py # a script with various functions that enables us to effectively interact with our website
Let's look at the following illustration to have a clear understanding of the above-mentioned file structure:
manage.py
fileThe manage.py
file has various functions that enable us to effectively interact with our website. It gives us control as we can specify users, provide credentials, adjust migrations to the database, and, most importantly, run a server on the local host. The server defaults to port 8000
.
Typing the following command in the terminal displays all the options related to the manage.py
.
python manage.py --help
Some of the options under manage.py
are explained below:
changepassword
: This is used to change a user's password to the admin dashboard (created by Django) of the application.
createsuperuser
: This adds a new user with their authentication credentials.
migrate
: This performs changes made to modules to the database schema.
check
: This identifies any errors on an application.
runserver
: This hosts the application on a server on the localhost.
Further descriptions of all the commands can be found in the official documentation of Django.
manage.py
scriptWe can create a Django app using the following command (for further details, visit this Answer on creating an app in Django).
python manage.py startapp educative
Once we have executed the above given command, we'll end up having the following file structure for our project.
Free Resources