← Back to Django Course | Chapter 1: Django Fundamentals & Setup | Lesson 1 of 9

Introduction to Django

Django is a helper that does a lot of the boring, repetitive work for you so you can build a website faster.

What Is Django?

Django is a high-level Python web framework that lets you build websites by writing Python code instead of reinventing common features like URL routing, database access, and forms from scratch.

Note: Framework means Django gives you the skeleton of a web application; you fill in the specific logic.

Example: What Is Django?

A Django view is just a Python function that takes a request and returns a response — this is a complete, working page in four lines.

markup
from django.http import HttpResponse

def home(request):
    return HttpResponse("Hello from Django!")
{# Django-only code -- models.py/views.py/urls.py/settings.py snippets, or template markup using Django template tags/variables -- can't run standalone via Judge0 or the browser preview, since it needs a real Django project. Only this course's pure-Python examples (example_lang == 'python', no Django imports) are actually runnable, so those still get the button below. #}

What You Can Build With Django

Django is used to build many kinds of sites: blogs, e-commerce stores, social networks, and internal admin tools, because it handles the common parts every website needs.

Note: The same framework that runs a small blog can also scale up to a large social platform.

Example: What You Can Build With Django

The same view-returns-a-response pattern that builds this tiny blog page scales up to e-commerce stores, social feeds, and admin dashboards — Django doesn't care what the content is.

markup
from django.http import HttpResponse

def blog_home(request):
    posts = ["Welcome to my blog", "Django is fun", "Learning MVT"]
    return HttpResponse("<br>".join(posts))
{# Django-only code -- models.py/views.py/urls.py/settings.py snippets, or template markup using Django template tags/variables -- can't run standalone via Judge0 or the browser preview, since it needs a real Django project. Only this course's pure-Python examples (example_lang == 'python', no Django imports) are actually runnable, so those still get the button below. #}

Django vs Writing Raw Python for the Web

Without Django you would have to manually parse HTTP requests, build your own URL router, and write raw SQL for every database query; Django gives you all of that ready to use.

Warning: Skipping a framework entirely is possible but means rebuilding basic plumbing every project.

Example: Django vs Writing Raw Python for the Web

path() parses the URL and converts <int:article_id> straight into a Python int argument for your view — without Django you'd hand-write regex parsing and type conversion yourself.

markup
from django.urls import path
from . import views

urlpatterns = [
    path('articles/<int:article_id>/', views.article_detail),
]
{# Django-only code -- models.py/views.py/urls.py/settings.py snippets, or template markup using Django template tags/variables -- can't run standalone via Judge0 or the browser preview, since it needs a real Django project. Only this course's pure-Python examples (example_lang == 'python', no Django imports) are actually runnable, so those still get the button below. #}
Common Mistakes
  1. Assuming Django is a programming language instead of a Python web framework.
  2. Expecting Django to work without Python already installed on the machine.
  3. Confusing Django (the backend framework) with a frontend JavaScript framework like React.
Chapter Summary
  • Django is a free, open-source web framework written in Python.
  • It provides ready-made tools for URLs, databases, templates, and admin panels.
  • Django follows the "batteries included" philosophy, so most common features are built in.
  • Companies like Instagram and Pinterest have used Django to build large websites.

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.