Help Center

Python - Django

Django is a popular open-source web development framework based on Python. It provides a set of tools and libraries to simplify building web applications efficiently and securely.

Some features of Django include:

MVT (Model-View-Template): Django uses a design pattern that separates application logic into model, view, and template for a modular structure.

ORM (Object-Relational Mapping): Django offers an ORM system that lets you interact with the database through Python objects instead of raw SQL.

Django Admin: provides a customizable administration interface to manage database data without having to program it.

Built-in security: Django includes security measures to protect against common vulnerabilities such as SQL injection, CSRF, and secure password management.

In summary, Django is an open-source web development framework based on Python that offers a solid MVC architecture, an integrated ORM for interacting with databases, a built-in content administration system (CMS), and a strong focus on security. Thanks to its clean design and wide range of libraries and modules, Django makes it easy to build robust and scalable web applications, making it a popular choice for developers looking for an efficient way to create websites and web apps.

Project structure

text
.
├── compose.yaml
├── app.Dockerfile
├── app
    ├── requirements.txt
    └── manage.py

Application deployment

Go to the directory that contains the files needed to build the container:

text
cd /root/stack/python/django

Then start the application:

text
docker compose up -d

Useful commands:

List the containers that are running:

text
docker compose ps

Stop and remove the application:

text
docker compose down

Rebuild the application after making changes to the code:

text
docker compose --build -d

Troubleshooting

If you need to run model migrations for your application to work, you can follow these steps:

  1. First, make sure the application is running:
text
$ docker compose up --build -d
  1. Run the following command to see a list of active containers. In the NAMES column you’ll find the container’s name:
docker ps
  1. Finally, run the following commands replacing NOMBRE with your container’s name:
text
docker exec -ti NOMBRE python3 manage.py makemigrations
docker exec -ti NOMBRE python3 manage.py migrate
  1. Finally, rebuild the application:
text
docker compose up --build -d