Django Project and Django App Setup
Now, its time to install django and set up a django project and django app
First of all, open VS code and then open the directory where we have created our virtual environment.
Now, in the terminal, we need to activate our virtual environment.
For Windows OS
env\Scripts\activate
For Linux Based OS
source env/bin/activate
After that, we need to install django in our virtual environment
pip install django
This command installs the latest version of django
Once the django is installed, you can verify the installation by using this command
pip list
Now, we need to create a requirements.txt file that stores the project dependencies information.
pip freeze > requirements.txt
This file contains all the libraries, modules, and packages along with the version number that is installed in our virtual environment.
Since, our django is installed, now we can create a django project. To create a brand new django project, we need to execute this command:
django-admin startproject mysite
mysite is the name of our django project
If you expand the mysite folder, you will get to see various python files and folders. Currently, you don't need to worry about what these files do. We will eventually learn all of these things later on.
After creating django project, we need to verify, whether everything is working fine or not. For that, we have to start the development server.
First, move to the mysite directory and make sure the virtual environment is activated.
cd mysite
Now, to start the django development server, we have to execute this command
python manage.py runserver
Open your browser and visit this URL : 127.0.0.1:8000/
If you can see a page that tells the install worked successfully then you are ready to go.
Now stop the development server by pressing Control + C.
In Django, we have a concept of app. You can think app as a separate entity in the website that does only similar kinds of work.
For example, if you have a blogging website made with django, then your entire blogging website is a django project and in the blogging website, we have some small-small components that do certain task like category, post, and comment. These are all your django apps.
In this vaccination scheduling application, we need to create various django apps. So, lets learn how create it.
First of all, we will create vaccine app.
python manage.py startapp vaccine
We also need to create various other apps like user, center, campaign, vaccination
python manage.py startapp user
python manage.py startapp center
python manage.py startapp campaign
python manage.py startapp vaccination
After creating django 5 different django app, we need to register these apps in our django project. If you don't register these apps, django wont be able to find your app.
To register the django apps, open settings.py file located in mysite folder. [mysite/mysite/settings.py]
Under the INSTALLED_APPS section, append the following code.
'vaccine.apps.VaccineConfig',
'user.apps.UserConfig',
'center.apps.CenterConfig',
'campaign.apps.CampaignConfig',
'vaccination.apps.VaccinationConfig',
In this way, we have successfully created a django project, 5 different django apps and registered them in our django project.
Now, we need to move all our changes to the staging area.
First of all, move to the root directory of our project
cd ../
git add .
After that, we have to commit the changes
git commit -m "Project Configurations"
Now, push the changes to the remote repository
git push origin main