I am using Django 1.8 with Python 3.4, I need to show the data of a table with ListView
but it does not show me anything or show me any error.
Here is the code:
models.py
class Tipo_almacen(models.Model):
descripcion = models.CharField(max_length=50)
class Meta:
db_table = 'Tipo_almacen'
verbose_name_plural = "Tipo de Almacenes"
verbose_name = "Tipo de Almacen"
def __str__(self):
return self.descripcion
views.py
from django.shortcuts import render
from mantenimiento.forms import Tipo_almacenForm
from django.http import HttpResponseRedirect
from django.views.generic import ListView
from appkardex.models import Tipo_almacen
def menu(request):
return render(request, 'main.html')
class ListaTipoAlmacen(ListView):
model = Tipo_almacen
template_name = 'cruds/lista_tipo_almacen.html'
def get_context_data(self, **kwargs):
context = super(ListaTipoAlmacen, self).get_context_data(**kwargs)
lista_tipo_almacen = Tipo_almacen.objects.all()
context['lista_tipo_almacen'] = lista_tipo_almacen
return context
urls.py
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^', views.menu),
url(r'^$', ListaTipoAlmacen.as_view(), name='lista_tipo_almacen')
] + static(settings.STATIC_URL)
main.html
<a href="{% url 'lista_tipo_almacen' %}">Tipo almacen</a></li>
tipo_tipo_almacen.html
{% extends "main.html" %}
{% block contenido %}
<h1>Tipo Almacen</h1>
<ul>
{% for lista in lista_tipo_almacen %}
<li>{{ lista.descripcion }} </li>
{% endfor %}
</ul>
{% endblock %}
Waiting for your prompt help.