# Getting Started with Django

The "**People Records"** project is a beginner-friendly web application built with Django, utilizing basic HTML, CSS, and Bootstrap. It enables users to perform essential CRUD (Create, Read, Update, Delete) operations. Additionally, the application features a custom login system integrated with Django’s admin functionality for user authentication management. This project is designed to showcase fundamental coding principles and core functionalities.

---

# Setting Up a Django Project

Before starting a Django project, the first step is to create a virtual environment.

## Creating a Virtual Environment

Navigate to the directory where you want to set up your project, then run the following command:

```powershell
python -m venv "Your Environment Name"
```

1. Once the virtual environment is created, navigate to its directory using the `cd` command. Then, go to the `scripts` folder and execute the `activate` script to activate the virtual environment. In summary, follow these steps:
    

```powershell
directory > cd "Your Environment Name"/Scripts/
directory > .\\activate
```

## Creating A Django Project

To start a Django project, use the following command:

```powershell
django-admin startproject "Project Name"
```

In Django, a single project can consist of multiple apps.

After creating the project, a project directory will be generated, containing several important files. Inside this directory, there will be another folder with the same project name, which holds essential configuration files that will be discussed later. Additionally, the project directory includes `manage.py`, a crucial script used for running the server, applying migrations, and performing various other functions.

**Files Included in the Project :**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740233336297/6ba35768-3db7-425c-b3b0-b80faffe376a.png align="center")

This basic project currently contains no additional functionality, so running it will only display the default boilerplate template.

To start the project, execute the following command in the terminal:

```bash
python manage.py runserver
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740233435952/f4b9890e-bb62-4571-bc30-04a3c4efe14e.png align="center")

**Django Boiler Plate**

---

## Creating an App

To create a new app in Django, use the following command:

```bash
django-admin startapp "App Name"
```

This will generate an app directory inside the project folder, alongside the main project directory. The newly created app folder will contain the following essential files:

**Files Inside the App Directory :**

`__init__.py` → May include the main function (to be defined later). `admin.py` → Used to register models created in [models.py](http://models.py) for database management. `apps.py` → Handles app-specific configurations. `models.py` → Defines database models that will be stored in the database. `tests.py` → Used for writing test cases to verify functionality. `views.py` → Contains functions that handle requests and render responses for the frontend.

**Adding the App to Django Settings :**

To integrate the newly created app into the project, add it to the `INSTALLED_APPS` list in the `settings.py` file located inside the main project folder.

**Defining URL Paths :**

Next, the app’s URLs need to be linked to the main project's URL configuration. This is done by modifying the [urls.py](http://urls.py) file in the main project directory as shown below:

```python
from django.contrib import admin
from django.urls import path, include

urlpatterns = [    
	path('admin/', admin.site.urls),    
	path("", include("practice_app.urls")),
]
```

**In the above code :**

* The `path` and `include` functions are imported from `django.urls`.
    
* The `admin` module is imported by default.
    
* The `urlpatterns` list maps URL paths, where `"practice_app.urls"` refers to the `urls.py` file inside the `practice_app` directory, which contains all the necessary routes for the app.
    

---

Stay tuned for the next section,

where we'll dive into implementing **CRUD** **operations** in Django! 🚀

![](https://media1.giphy.com/media/v1.Y2lkPTc5MGI3NjExZXU1YmwxOTVodTZ5YWJ2NmFrazd4d2NvZGh4bmFmNzR1MGF6M2Y2OSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/l3V0mgFspVuDAJK9y/giphy.gif align="center")

---
