Fundamentos de Django
¿Qué es Django?
¿Cómo instalar Django?
Entendiendo la arquitectura de Django
Qué es el patrón MVT (Model, View y Template)
La M en el Patrón: Modelo
Introducción a Modelos y Bases de Datos
Manejo Avanzado de Modelos y Bases de Datos
Gestión de Modelos y Bases de Datos en Django con SQLite
Inserción de Datos con Django
Actualización y Eliminación de Datos en Django
Relaciones y Asociaciones entre Modelos
Creación y Gestión de Relaciones entre Modelos en Django
Relaciones Muchos a Muchos (N:N) en Django
Relaciones Uno a Uno (1:1) en Django
Queries y Filtros en Django: Optimización y Estrategias Avanzadas
Configuración de URLs y Vistas Avanzadas
Gestión de URLs en Django: Configuración, Rutas y Mejores Prácticas
Vistas Basadas en Clases en Django
La T en el Patrón: Plantillas o Templates
Personalización de Interfaz con Plantillas en Django
Desarrollo de Aplicaciones en Django
Configuración del Proyectos en Django
Creación del Modelo para la Aplicación 'Products' en Django
Cómo Crear Migraciones de Datos en Django
Creación de la Aplicación 'Products' con Formularios en Django
Integracion de TailwindCSS en Django
Django Admin
Manejo de Sesiones en Django
Manejo de Órdenes en CoffeShop
Manejo de Pedidos en CoffeShop
Mixings en vistas basadas en clases
Agregar productos a la orden
Django Rest Framework
Django REST Framework
Despliegue de aplicaciones Django
Configurar PostgreSQL en AWS con Django
Variables de entorno en Django
¿Cómo usar Unit Testing en Django?
Debugging en Django
Desplegar aplicaciones de Django en AWS
You don't have access to this class
Keep learning! Join and start boosting your career
Models in Django are used to store data. We will create a class called Cart
, which inherits from models.Model
. This class will have a title
field of type models.TextField
, with a max_length
defined to limit the amount of text it can accept.
from django.db import modelsclass Cart(models.Model):title = models.TextField(max_length=255)
Views in Django are responsible for fetching data and returning it to the template. A view is defined as a method that receives a request
and returns a response
. We will use render
to pass the request and the template to the view.
from django.shortcuts import renderdef myView(request):car_list = [{'title': 'BMW'}, {'title': 'Mazda'}] context = {'car_list': car_list} return render(request, 'myFirstApp/carlist.html', context)
Templates are HTML files that receive data from views. For Django to recognize them, we create a folder called templates
inside our application and then another one with the name of the application. Inside, we create the carlist.html
file.
<html><head> <title>CarList</title></head></head><body><body> <h1>CarList</h1> <ul>{% for car in car_list %} <li>{{ car.title }}</li>{% endfor %} </ul></body></html> </html>
In order for Django to recognize our new application, we need to add it to the INSTALLED_APPS
list in the settings.py
file.
INSTALLED_APPS = [ ... ' myFirstApp', ]
We create an urls.py
file in our application and define the path for our view. Then, we include this configuration in the main urls.py
file of the project.
from django.urls import pathfrom.views import myView urlpatterns = [ path('carlist/', myView, name='carlist'), ]
from django.contrib import adminfrom django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path('myFirstApp/', include('myFirstApp.urls')), ] ]
We pass the data from the view to the template using a context. In the template, we use Django tags to iterate over the data and display it.
{% for car in car_list %} - {{ car.title }}
{% endfor %}
Contributions 29
Questions 3
Want to see more contributions, questions and answers from the community?