Now that you have successfully installed Django, let’s explore by creating a project. Every app that we create in Django is called a project. To create a project in Django on either Windows or Linux, you need to open a terminal or command prompt on your system and use the code given below:
$ django-admin startproject firstproject
Now, this code will create a folder with the name “firstproject” with the structure as follows:
firstproject/
manage.py
firstproject/
__init__.py
setttings.py
urls.py
wsgi.py
The structure of the project is described below:
- manage.py: The file is created under Django-admin which is intended for interaction with the project. You can also get a complete list of commands that are accessible by using the command below:
$ python manage.py help
- “firstproject/” subfolder: This folder contains all important files of the project such as:
- __init__.py – This file contains the main code of your project written in Python language.
- settings.py – The file contains the project settings.
- ursl.py – In this file, you will find all links to your projects and the functions used to call them.
- wsgi.py – This file is used when you want to deploy your project over WSGI.
Setting up the Project
As we just discussed that the project will be set up in the firstproject/setting.py file and you can use the following settings for your project:
DEBUG = True
The option will let you check if the project is in debug mode or not. The debug mode is useful to get information about the errors in the project. The value ‘True’ for DEBUG option cannot be used for live projects. But the value of DEBUG has to be set to ‘True’ for serving static files to the server. The following settings are to be done in the development mode:
DATABASES = {
‘default’ : {
‘ENGINE’ : ‘django.db.backend.sqlite3’,
‘NAME’ : ‘database.sql’,
‘USER’ : ‘’,
‘PASSWORD’ : ‘’,
‘HOST’ : ‘’,
‘PORT’ : ‘’,
}
}
Django supports a ‘Database’ dictionary where the database can be set. The settings shown above are used for SQLite Engine for setting up the database.
Now, to check whether the project is working correctly or not, use the following code in your command prompt or terminal:
$ python manage.py runserver
The above code will give the following output:
Validating models…
0 errors found
January 05, 2023 – 01:09:22
Django version 2.2.5, using settings ‘myproject.settings’
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C