Django is a “batteries-included” framework written in Python. This means it comes with almost everything a developer needs right out of the box—like security, database management, and an admin panel. So, you can focus on writing your app instead of the boring plumbing.
Example: If you are building a blog, you don’t need to write code to “log in” or “save a post” from scratch; Django has those features ready for you to turn on.
Key features
Django offers ORM, admin UI, templating, security helpers, and routing out of the box, so small teams can deliver faster. Example: create models and immediately manage data via the admin panel.
Installation
Install Django using pip with this command: pip install django and start a project: python -m django startproject mysite
MVT (Model‑View‑Template)
Django follows the Model-View-Template pattern. It’s a way of organizing code so that the data (Model), the logic (View), and the design (Template) are kept in separate folders, making the project easier to manage as it grows.
Example: Imagine a restaurant. The Model is the pantry (data), the View is the chef (logic), and the Template is the plate presentation (what the customer sees).
Models (The Data)
A Model is a Python way of describing your database. Instead of writing complex SQL code to create tables, you just write a simple Python class. Django then translates that class into a table where your website’s information is stored.
Example: For an e-commerce site, a Product model would define that every item needs a Name (text), a Price (number), and a Description.
Views (The Brains)
The View is a function that takes a request from a user (like clicking a link) and decides what to do next. It fetches the right data from the Model and sends it to the Template to be displayed on the screen.
Example: When you click “View Profile”, the View finds your specific user info in the database and sends it to the page that shows your bio and photo.
Templates (The Design)
Templates are HTML files that define how your website looks. However, they aren’t static; they use “placeholders” that Django fills in with real data before the page is sent to your browser.
<>
Example: A template might say Hello, {{ user_name }}!. When you log in, Django replaces {{ user_name }} with “Alex” automatically.
URLs (The Navigator)
URL configuration is like a GPS for your website. It maps a specific web address (like /contact/) to a specific View function. When a user types an address, Django looks at this list to figure out where to send them.
Example: You tell Django that whenever someone types www.yoursite.com/pizza, it should run the show_pizza_menu function.
The Admin Interface
One of Django’s “killer features” is the automatic Admin Panel. Once you define your Models, Django creates a professional, secure area where you can add, edit, or delete data without writing a single line of extra code.
Example: A news editor can log into the /admin area to type up a new article and hit “Save” without ever seeing the actual code of the website.
ORM (Object-Relational Mapper)
The ORM is the “translator” between Python and the Database. It allows you to interact with your data using Python code instead of learning a different language like SQL, making it much harder to make mistakes or get hacked.
Example: Instead of writing SELECT * FROM Users WHERE id=1, you just write User.objects.get(id=1) in Python.
Forms
Django Forms handle the heavy lifting of taking data from a user (like a signup sheet), checking if the email is valid, and making sure no “bad code” is being submitted.
Example: If a user forgets to include the “@” in their email on your “Contact Us” page, the Django Form will automatically stop the submission and show an error message: “Please enter a valid email”.