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.
This work is under a Attribution-NonCommercial-NoDerivatives 4.0 International license.
Desafíos de programación atemporales y multiparadigmáticos
Te encuentras ante un librillo de actividades, divididas en 2 niveles de dificultad. Te enfrentarás a los casos más comunes que te puedes encontrar en pruebas técnicas o aprender conceptos elementales de programación.
Buy the bookWill you buy me a coffee?
This is how I keep writing without ads or paywalls.
Sure, it's on me!
Comments
There are no comments yet.