Rendering Tables

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/

Edit post (Admin)

Comment on This Data Unit