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 are:
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 allows interacting with the database through Python objects instead of direct SQL.
Django Admin CMS: provides a customizable administration interface to manage database data without needing 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 strong attention to security. Thanks to its clean design and wide range of libraries and modules, Django makes building robust and scalable web applications easier, making it a popular choice for developers seeking an efficient way to create websites and web applications.
Project structure
.
├── compose.yaml
├── app.Dockerfile
├── app
├── requirements.txt
└── manage.py
Application deployment
We go to the directory that contains the files needed to build the container:
cd /root/stack/python/django
And start the application:
docker compose up -d
Useful commands:
View running containers:
docker compose ps
Stop and remove the application:
docker compose down
Rebuild the application after making changes to the code:
docker compose up -d --build
Troubleshooting
If you need to run model migrations for your application to work, you can follow these steps:
- First, make sure the application is running:
$ docker compose up --build -d
- Run the following command to see a list of active containers. In the NAMES column you will find the container’s name:
docker ps
- Finally, run the following commands replacing NAME with the name of your container:
docker exec -ti NAME python3 manage.py makemigrations
docker exec -ti NAME python3 manage.py migrate
- Lastly, rebuild the application:
docker compose up --build -d