1. Introduction

Welcome to a course to learn the basics of Django. Starting from scratch, you will learn to build a blog with Django.

Django is a web framework for building web applications in Python. It is perfect for beginners and experts alike, and it is one of the most popular languages today. Among the websites that use Django are Instagram, Pinterest, The Washington Times, Mozilla, The Guardian, and many more.

To follow along with the course, I ask for the following requirements:

  • Basic knowledge of Python.
  • Basic knowledge of HTML and CSS.
  • Docker and Docker Compose installed.
  • An IDE or rich editor such as VS Code, Sublime Text, PyCharm, Jetbrains, etc.

Are you ready? Let's get to it!

Preparing the development environment

Docker

Docker is a software platform that allows developers, system administrators, and other users to package, distribute, and run applications in containers. Containers are processes that are independent of one another and can have their own software versions, libraries, and configurations. Very useful for having a development environment that does not conflict with other projects.

Create a Dockerfile at the root of your project with the following content:

FROM python:3.12-slim

# Prevents Python from writing pyc files to disc (equivalent to python -B option)
ENV PYTHONDONTWRITEBYTECODE=1
# Prevents Python from buffering stdout and stderr (equivalent to python -u option)
ENV PYTHONUNBUFFERED=1

# Sets python path to be able to import modules
ENV PYTHONPATH=":/usr/src/app"
# set work directory
WORKDIR /usr/src/app

# set time
RUN ln -fs /usr/share/zoneinfo/Europe/Madrid /etc/localtime
RUN dpkg-reconfigure -f noninteractive tzdata

# install software
RUN apt-get update && apt-get install -y \
    build-essential \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# install dependencies
COPY requirements.txt .
RUN pip3 install --no-cache-dir --upgrade pip
RUN pip3 install --no-cache-dir -r requirements.txt

You have just defined an image. Images are used to create containers. A container is an instance of an image. To create a container, you need a compose.yml file.

Create a compose.yml file at the root of your project with the following content:

services:

  django:
    build: .
    volumes:
      - .:/usr/src/app/
    ports:
    - "8000:8000"

Your development environment is now ready.

The next step will be to create a Django project.

Building SPAs with Django and HTML Over the Wire: Learn to build real-time single page applications with Python

Building SPAs with Django and HTML Over the Wire: Learn to build real-time single page applications with Python

The HTML over WebSockets approach simplifies single-page application (SPA) development and lets you bypass learning a JavaScript rendering framework such as React, Vue, or Angular, moving the logic to Python. This web application development book provides you with all the Django tools you need to simplify your developments with real-time results.

Buy the book

Help me keep writing

Every coffee gives me a push toward the next article.

Comments

There are no comments yet.