It doesn't show me the content of the detail view, it just shows the title "Detail cleaning event in calendar".
models.py
class EventTankCleaning(models.Model):
installation_TankCleaning = models.ForeignKey(Installation,on_delete=models.CASCADE,null=True, blank=True)
startdatetime_TankCleaning = models.DateField('Fecha y hora de comienzo de limpieza', null=True, blank=True)
observations_TankCleaning = models.TextField('Observaciones', null=True, blank=True)
class Meta:
verbose_name = 'Añadir limpieza de tanque'
verbose_name = 'Añadir limpiezas de tanques'
def __str__(self):
return str(self.installation_TankCleaning)
urls.py
path(
'detail_eventTankCleaning/<pk>/',
views.DetailEventTankCleaning.as_view(),
name='detail_eventTankCleaning',
),
view.py
class DetailEventTankCleaning(LoginRequiredMixin,DetailView):
model = EventTankCleaning
template_name = "cleaning/detail_cleaning.html"
login_url = reverse_lazy('users_app:user-login')
detail_cleaning.html
div class="container">
<div class="row">
<div class="offset-lg-0 col-2"></div>
<div class="col-lg-12 col-md-8">
<div class="alert border m-3 bg-light" role="alert">
<h3 class="text-dark">Detalle evento de limpieza en calendario</h3>
{{ installation_TankCleaning }}
{{ startdatetime_TankCleaning }}
{{ observations_TankCleaning }}
</div>
</div>
<div class="offser-lg-0 col-2"></div>
</div>
</div>
The error occurs because you only put in the template the field of the object installation_TankCleaning, startdatetime_TankCleaning and observations_TankCleaning but not the context that carries the object. By default, the 'object' context is returned in order to access the fields of the object. It is done this way:
You can see this in detail in the DetailView's get_context_data() function here: https://ccbv.co.uk/projects/django/3.1/django.views.generic.detail/DetailView/#get_context_data