Rendering Tables

Created on Sept. 21, 2012, 12:40 p.m. by Hevok & updated by Hevok on May 2, 2013, 5:26 p.m.

To create a table from a model django-table2 can be used.

Add django-table2 to the requirements and config file under installed apps: ::

nano requirement/project.txt
-e git://


In the view pass the data, e.g.: ::

from django.shortcuts import render

from data.models import entry

def view(request):
    return render(request, 'entries.html', {'entries': Entry.objects.all()})

In the template load django-tables2, its static files and render the tables: ::

nano entries.html
{# Exemplifies rendering of a table #}
<!doctype html>
        <link rel="stylesheet" href="{{ STATIC_URL }}django_tables2/themes/paleblue/css/screen.css" />
         {% render_table entries %}

If the static files are not rendered proably on deployment or need to be customized, copy the files into the respective media project directory: ::

cp -rf /home/user/project/env/src/django-tables2/django_tables2/static  /home/user/project/media/django_tables2/

Tags: tutorial, table, django
Parent: Web Framework

Update entry (Admin) | See changes

Comment on This Data Unit