Django Cheat Sheet

The Django Cheat Sheet is a quick reference list of many of the most commonly used commands and techniques for Django.

What is Django?

Django is a python-based web framework used for the rapid development of web applications.

Django Cheat Sheet

Installing Django

pip install django

Create a project

django-admin startproject projectName

Start a server

python runserver

Django Model

from django.db import models

class Book(models.Model):


from django.http import HttpResponse

def index(request):
    return HttpResponse("Django CodeWithBeri Cheatsheet")

HTML Template

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>CodeWithBeri Cheatsheet</title>
    <h1>This is a sample template file.</h1>

Function-Based Views

from django.http import HttpResponse

def index(request):
    return HttpResponse("This is a function based view.")

Class-Based Views

from django.views import View

class SimpleClassBasedView(View):
    def get(self, request):
        pass # Code to process a GET request


from django.contrib import admin
from django.urls import path, include
from . import views

urlPatterns = [
    path('', views.index, name='index'),
    path('about/', views.about, name='about'),
    path('contact/', include('contact.urls')),

Django form

from django import forms

# creating a form
class DjangoForm(forms.Form):
    name = forms.CharField()
    description = forms.CharField()

Create an app

python startapp app_name

Register app in the


Configuring templates in

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ["templates"],
        'APP_DIRS': True,
        'OPTIONS': {
            # some options here

Create a migration file

python makemigrations

Applying the migration

python migrate

Creating the admin user

python createsuperuser

Redirect method

from django.shortcuts import render, redirect

def redirecting(request):
    return redirect("")

Note: If you are a beginner in python web development then I will suggest you learn flask first. For helping you, I also create a flask cheat sheet.


The Django framework is an open-source web framework that encourages rapid development and clean design. It is one of the most popular frameworks for the Python programming language.

The Django framework has a lot of features like user authentication, administration, and templates. The Django cheat sheet is a great resource for beginners who want to learn about the framework.

Leave a Comment