This guide gets you from zero to a working Django application in under 30 minutes. Perfect for developers who want to see Django in action quickly or need a rapid refresher on Django fundamentals.
Before starting, ensure you have:
python --version)pip --version)# Create project directory
mkdir django_quickstart
cd django_quickstart
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
# Install Django
pip install django
# Verify installation
python -m django --version
# Create project
django-admin startproject quickstart .
# Verify structure
ls -la
# You should see: manage.py, quickstart/
# Apply initial migrations
python manage.py migrate
# Create superuser (follow prompts)
python manage.py createsuperuser
# Start development server
python manage.py runserver
✅ Success Check: Visit http://127.0.0.1:8000/ - you should see Django's welcome page!
Let's build a simple blog to demonstrate Django's core concepts.
# Stop server with Ctrl+C, then:
python manage.py startapp blog
# Register app in quickstart/settings.py
Add to INSTALLED_APPS in quickstart/settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog', # Add this line
]
Edit blog/models.py:
from django.db import models
from django.contrib.auth.models import User
from django.urls import reverse
class Post(models.Model):
title = models.CharField(max_length=200)
content = models.TextField()
author = models.ForeignKey(User, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ['-created_at']
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('post_detail', kwargs={'pk': self.pk})
# Create migration
python manage.py makemigrations blog
# Apply migration
python manage.py migrate
Edit blog/admin.py:
from django.contrib import admin
from .models import Post
@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
list_display = ['title', 'author', 'created_at']
list_filter = ['created_at', 'author']
search_fields = ['title', 'content']
Edit blog/views.py:
from django.shortcuts import render, get_object_or_404
from django.views.generic import ListView
from .models import Post
class PostListView(ListView):
model = Post
template_name = 'blog/post_list.html'
context_object_name = 'posts'
paginate_by = 5
def post_detail(request, pk):
post = get_object_or_404(Post, pk=pk)
return render(request, 'blog/post_detail.html', {'post': post})
def home(request):
recent_posts = Post.objects.all()[:3]
return render(request, 'blog/home.html', {'posts': recent_posts})
Create template directories:
mkdir -p blog/templates/blog
Create blog/templates/blog/base.html:
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}Quick Blog{% endblock %}</title>
<style>
body { font-family: Arial, sans-serif; margin: 40px; }
.header { background: #333; color: white; padding: 20px; margin: -40px -40px 40px -40px; }
.post { border-bottom: 1px solid #eee; padding: 20px 0; }
.meta { color: #666; font-size: 0.9em; }
a { color: #007bff; text-decoration: none; }
a:hover { text-decoration: underline; }
</style>
</head>
<body>
<div class="header">
<h1><a href="{% url 'home' %}" style="color: white;">Quick Blog</a></h1>
<nav>
<a href="{% url 'home' %}" style="color: white;">Home</a> |
<a href="{% url 'post_list' %}" style="color: white;">All Posts</a> |
<a href="{% url 'admin:index' %}" style="color: white;">Admin</a>
</nav>
</div>
{% block content %}{% endblock %}
</body>
</html>
Create blog/templates/blog/home.html:
{% extends 'blog/base.html' %}
{% block content %}
<h2>Welcome to Quick Blog</h2>
<p>A simple Django blog built in 10 minutes!</p>
<h3>Recent Posts</h3>
{% for post in posts %}
<div class="post">
<h4><a href="{% url 'post_detail' post.pk %}">{{ post.title }}</a></h4>
<p class="meta">By {{ post.author }} on {{ post.created_at|date:"M d, Y" }}</p>
<p>{{ post.content|truncatewords:30 }}</p>
</div>
{% empty %}
<p>No posts yet. <a href="{% url 'admin:index' %}">Create one in the admin!</a></p>
{% endfor %}
<p><a href="{% url 'post_list' %}">View all posts →</a></p>
{% endblock %}
Create blog/urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name='home'),
path('posts/', views.PostListView.as_view(), name='post_list'),
path('post/<int:pk>/', views.post_detail, name='post_detail'),
]
Update quickstart/urls.py:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('blog.urls')),
]
# Start development server
python manage.py runserver
Visit these URLs to test your application:
# Check if port is in use
python manage.py runserver 8080
# Or kill existing process
lsof -ti:8000 | xargs kill -9 # macOS/Linux
# Check template directory structure
ls -la blog/templates/blog/
# Ensure APP_DIRS is True in settings.py
# Reset database
rm db.sqlite3
python manage.py migrate
python manage.py createsuperuser
Now that you have a working Django application:
# Start new project
django-admin startproject myproject
# Create new app
python manage.py startapp myapp
# Database operations
python manage.py makemigrations
python manage.py migrate
# User management
python manage.py createsuperuser
# Development server
python manage.py runserver
# Django shell
python manage.py shell
# In Django shell (python manage.py shell)
from blog.models import Post
from django.contrib.auth.models import User
# Create objects
user = User.objects.get(username='admin')
post = Post.objects.create(
title='My First Post',
content='Hello, Django!',
author=user
)
# Query objects
Post.objects.all()
Post.objects.filter(author=user)
Congratulations! You've built a complete Django blog application from scratch in under 30 minutes. This quick start guide demonstrates Django's power for rapid development while following best practices for maintainable, scalable applications.
Your First Django "Hello World"
Creating your first "Hello World" application in Django demonstrates the fundamental concepts of views, URLs, and templates. This guide walks you through building a simple but complete Django application from scratch.
How Django Handles Requests
Understanding Django's request-response cycle is fundamental to building effective web applications. This comprehensive guide explores every step of how Django processes HTTP requests, from the initial URL resolution to the final response delivery.