Introduction to Django
In this page:
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.
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.
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.
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. #}
- Assuming Django is a programming language instead of a Python web framework.
- Expecting Django to work without Python already installed on the machine.
- Confusing Django (the backend framework) with a frontend JavaScript framework like React.
- 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.
Chapter Quiz — Complete all 9 topics to unlock
0/9 topics done
Complete these topics first: