0

I am relatively new in Django and could not find any answer here on why my table from django_tables2 is not rendering nice pagination buttons. Here follows the codes:

models.py

class IDOC(models.Model):
    on_delete=models.SET_NULL, null=True)
    sample_id = models.CharField(max_length=200)
    lon = models.FloatField(null=True, blank=True)
    lat = models.FloatField(null=True, blank=True)
    dp_position = models.IntegerField(null=True, blank=True, verbose_name='DP Position [-]')

    def __str__(self):
        return self.sample_id

tables.py

class IDOCTable(tables.Table):
    sediment_depth_m = NumberColumn()
    wl_m = NumberColumn()
    H_m = NumberColumn()
    idoc_mgl = NumberColumn()
    temp_c = NumberColumn()
    idoc_sat = NumberColumn()

    class Meta:
        model = IDOC
        template_name = "django_tables2/bootstrap-responsive.html"

views.py

def view():
    idoc_objects = IDOC.objects.all()
    idoc_show = flutb.IDOCTable(idoc_objects)
    context = {
               'idoc_table': idoc_show,
               }
    return render(request, 'flussdata/query.html', context)

flussdata/query.html

{% extends 'base.html' %}
{% load django_tables2 %}

{% block content %}
<div class="row">
    <div class="col-md">
        <div class="row">
            <div class="card card-body">
                <h3>Intragravel Dissolved Oxygen Content</h3>
                {% render_table idoc_table %}
            </div>
        </div>     
    </div>   
</div>

Then, my tables is rendered like this: enter image description here

Instead of the way it should, which I believe is like this:

enter image description here

  • Have you specified the templating for the table? https://django-tables2.readthedocs.io/en/latest/pages/custom-rendering.html#available-templates – Ben Jun 28 '22 at 17:34
  • Even if I do specify: DJANGO_TABLES2_TEMPLATE = "django_tables2/bootstrap.html" in the settings.py, the pagination buttons still don't render correctly. That is also the case if I remove the template assignment inside of the Meta of the class-based tables. – Beatriz Negreiros Jun 29 '22 at 09:09
  • Does the bootstrap stylings show up in the generated html? If yes, make sure you're importing the bootstrap css file into your template : see the last code chunk here: https://django-tables2.readthedocs.io/en/latest/pages/tutorial.html?highlight=maxcdn.bootstrapcdn.com#tutorial – Ben Jun 29 '22 at 17:40
  • Also, have you done "pip install django-bootstrap3" (or 4) and put bootstrap in the installed apps? see the installed apps in https://github.com/jieter/django-tables2/blob/master/example/settings.py . I haven't gotten good looking ones working either, so hope you'll answer your question if you get it worked out. – Levin Magruder Jun 30 '22 at 00:56
  • Thank you! Entering the stylesheet in the head template works but then by entire page template gets screwed up, probably because its stylesheet gets overwritten. Any ideas on how to handle that? Could I assign the stylesheet only to the table div in my template query.html? – Beatriz Negreiros Jun 30 '22 at 14:07
  • Load the bootstrap css first, and then your own css. That should set the precedence in the intended order. See: https://stackoverflow.com/a/5902873/2785080 for further info. – Ben Jul 01 '22 at 06:14

0 Answers0