Python for Data & Web
Python Django Basics
Django is a full-featured Python web framework that comes with everything a serious web app usually needs — database handling, an admin panel, and routing — built in from the start.
What Is Django?
Django is a "batteries included" framework: unlike a minimal library, it ships with an object-relational mapper (ORM) for talking to a database, a ready-made admin dashboard, user authentication, and a templating system, so you spend less time wiring things together.
pip install djangoProject vs App
A Django project is the overall website configuration, while an app is a self-contained module inside it that handles one feature, like blog posts or job listings. A single project can contain several apps, and apps can even be reused across projects.
django-admin startproject mysite
cd mysite
python manage.py startapp jobsThe MVT Pattern
Django organises code using Model-View-Template (MVT), its own take on the classic MVC pattern. The Model defines your data (usually as a Python class mapped to a database table), the View contains the logic that decides what data to show, and the Template is the HTML that displays it to the user.
| Part | Role |
|---|---|
| Model | Defines data structure, talks to the database |
| View | Logic that fetches data and picks a response |
| Template | HTML that renders the final page |
Running the Development Server
Once your project exists, Django's built-in server lets you preview it locally without any extra setup.
python manage.py runserverThis starts a local server, usually at http://127.0.0.1:8000/, and reloads automatically as you edit your code — similar in spirit to Flask's debug mode.
Django vs Flask: Which to Choose?
Flask is a lean, flexible library — great for small APIs, quick prototypes, or when you want to choose your own database and tools. Django is heavier but gives you a complete, consistent structure out of the box, which suits larger apps like e-commerce sites or platforms with logins, admin panels, and many database models.
If you are just learning web development or building a tiny API, start with Flask. Move to Django once your project needs user accounts, an admin interface, or several connected database models.
