Zeokav
Zeokav

Reputation: 1703

Django_tables2 - part of css not working

This is my first time working with the django_tables2 plugin - so naturally, I followed the installation and quick start guide in their docs.
I have pip-installed django-tables2, added 'django_tables2' to my installed apps, and made sure that 'django.template.context_processors.request' was in the template options.
However, I've come across a weird anomaly. I'm pasting my code below, for reference -

Views -

from django.shortcuts import render
from .models import VM

def people(request):
    return render(request, 'home.html', {'vms': VM.objects.all()})

home.html -

{% load render_table from django_tables2 %}
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="{% static 'css/bs.css' %}" />
    <link rel="stylesheet" href="{% static 'django_tables2/themes/paleblue/css/screen.css' %}" />
    <link rel="stylesheet" href="{% static 'css/style.css' %}" type="text/css" />
</head>
<body>
    <div class="col-sm-offset-2 col-sm-10 text-center">
        <h2 id="Text">VM List</h2>
        {% render_table vms %}
    </div>
</body>
</html>

As you can see, this is exactly what's given in the docs. However, while my table is somewhat formatted, it isn't completely the same as what I originally expected.

This is what I get -
My output

And this is something I should be getting, according to the docs. -

The correct stuff


Note that the django_tables2 css is in fact fetched. I kept an eye on the source files, and the screen.css under django_tables2 loads just fine.

EDIT - Inspect element of the tables. Everything has classes except the table itself (which should be paleblue). Adding that bit on the inspector works, but how do I do this via code? Shouldn't it happen by default?

Inspector

Upvotes: 3

Views: 1128

Answers (1)

Arpit Solanki
Arpit Solanki

Reputation: 9931

I saw this in the template tags code:

class OnTheFlyTable(tables.Table):
    class Meta:
        model = queryset.model

which is the default table rendered by django table since it does not include any css class you are seeing any css class in table tag.

Now from the docstrings in the code:

class OnTheFlyTable(tables.Table):
    class Meta:
        model = queryset.model
        attrs = {'class': 'paleblue'}

you have to use something like below to be able to use css classes for tables

References of files from I read this code:

Upvotes: 3

Related Questions