# Django Project Setup

Django is a powerful Python web framework that helps you build secure, scalable web applications quickly. In this blog, we’ll walk through a **complete Django project setup from scratch**, using clear commands and best practices.

This guide is perfect if you’re a beginner or setting up a fresh Django project for production or learning.

## Prerequisites

Before starting, make sure you have:

* Python **3.10+** installed
    
* Basic knowledge of terminal/command line
    
* `pip` (Python package manager)
    

Check your Python version:

```powershell
python --version
```

## Step 1: Create a Project Directory

First, create and move into a new directory for your project.

```powershell
mkdir django_project
cd django_project
```

## Step 2: Create a Virtual Environment (Recommended)

A virtual environment keeps your project dependencies isolated.

```powershell
python -m venv venv
```

Activate it:

### On Linux / macOS

```powershell
source venv/bin/activate
```

### **On Windows**

```powershell
venv\Scripts\activate
```

You should now see `(venv)` in your terminal.

## Step 3: Upgrade pip

Always keep pip updated.

```powershell
pip install --upgrade pip
```

## Step 4: Install Django

Install the latest stable version of Django.

```powershell
pip install django
```

Verify installation:

```powershell
django-admin --version
```

## Step 5: Create a Django Project

Now create your Django project.

```powershell
django-admin startproject config .
```

The dot (`.`) prevents creating an extra nested folder.

Your structure will look like:

```powershell
django_project/
├── config/
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   ├── asgi.py
│   └── wsgi.py
├── manage.py
└── venv/
```

## Step 6: Run Initial Migrations

Django uses migrations to manage database schema.

```powershell
python manage.py mimgrate
```

## Step 7: Create a Superuser (Admin)

To access Django admin panel:

```powershell
python manage.py createsuperuser
```

  
Enter:

* Username
    
* Email (optional)
    
* Password
    

---

## Step 8: Run the Development Server

Start the Django server:

```powershell
python manage.py runserver
```

Open your browser and visit:

```powershell
http://127.0.0.1:8000/
```

Admin panel:

```powershell
http://127.0.0.1:8000/admin/
```

Your Django project is now running!

---

## Step 9: Create a Django App

Create an app for your features (e.g., blog, users, core).

```powershell
python manage.py startapp blog
```

Project structure now:

```powershell
blog/
├── admin.py
├── apps.py
├── models.py
├── tests.py
├── views.py
└── migrations/
```

---

## Step 10: Register App in Settings

Open `config/`[`settings.py`](http://settings.py) and add your app:

```powershell
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'blog',
]
```

---

## Step 11: Create Models and Migrate

After writing models in [`models.py`](http://models.py):

```powershell
python manage.py makemigrations
python manage.py migrate
```

---

## Step 12: Freeze Dependencies (Best Practice)

Save installed packages:

```powershell
pip freeze > requirements.txt
```

Later you can install them using:

```powershell
pip install -r requirements.txt
```

---

## Common Django Commands Cheat Sheet

```powershell
python manage.py runserver
python manage.py startapp app_name
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
python manage.py shell
```

---

## Conclusion

Setting up a Django project is straightforward when you follow a structured approach. With virtual environments, clean project structure, and proper commands, you’re ready to build powerful web applications.
