Django Tutorial

Build your first Django web application with step-by-step instructions and code examples.

🚀 Get Started

Introduction to Django

Django is a high-level Python web framework that encourages rapid development and clean design. This tutorial will walk you through creating a simple blog application from scratch.

Installation

Step 1: Create Virtual Environment

python -m venv myenv
source myenv/bin/activate  # Windows: myenv\Scripts\activate

Step 2: Install Django

pip install django

Create Project

Step 1: Generate Project Structure

django-admin startproject myproject
cd myproject

Step 2: Run Development Server

python manage.py runserver

Visit http://127.0.0.1:8000 in your browser

Create App

Step 1: Generate Blog Application

python manage.py startapp blog

Step 2: Update Settings

INSTALLED_APPS = [
    ...
    'blog',
]

Define Models

from django.db import models

class Post(models.Model):
    title = models.CharField(max_length=200)
    content = models.TextField()
    pub_date = models.DateTimeField('date published')

Add this to blog/models.py

Register Admin

from django.contrib import admin
from .models import Post

admin.site.register(Post)

Create Admin User

python manage.py createsuperuser