Before we dive into building our movie database, let's briefly introduce Django. Django is a free, open-source web framework written in Python that enables rapid development of secure, maintainable websites. It provides an architecture, templates, and APIs to build web applications quickly and efficiently. Django is often used for building complex, data-driven websites, making it an ideal choice for a movie database.
from django.shortcuts import render, get_object_or_404, redirect from .models import Pelicula from .forms import PeliculaForm # Lo crearemos después
In Django, a project is divided into smaller units called apps. Each app represents a self-contained module of the project. Create a new app for our movie database by running: django pelicula
class PeliculaForm(forms.ModelForm): class Meta: model = Pelicula fields = ['titulo', 'director', 'año', 'genero', 'duracion_minutos', 'sinopsis'] widgets = 'sinopsis': forms.Textarea(attrs='rows': 4), 'año': forms.NumberInput(attrs='min': 1888, 'max': 2026),
INSTALLED_APPS = [ ... 'movies.apps.MoviesConfig', ] Before we dive into building our movie database,
from django import forms from .models import Pelicula
def movie_detail(request, pk): movie = Movie.objects.get(pk=pk) return render(request, 'movies/movie_detail.html', 'movie': movie) Django is often used for building complex, data-driven
Llegamos al punto de inflexión moderno: . Aunque muchos creen que Tarantino hizo un remake, la realidad es más compleja. Tarantino rinde homenaje al personaje de Corbucci.
def crear_pelicula(request): if request.method == 'POST': form = PeliculaForm(request.POST) if form.is_valid(): form.save() return redirect('lista_peliculas') else: form = PeliculaForm() return render(request, 'peliculas/formulario.html', 'form': form)
python manage.py makemigrations python manage.py migrate python manage.py runserver