1

I'm using django_talbes2 and the table renders correctly (in a sense that it displays all the information it should), but when I click on a column header to sort it or on a page number to go to the next page it "breaks" -- it returns to the home page and I'm not on the view which renders the table anymore.

Actually, the problem is VERY SIMILAR to the one described here

But the accepted solution wouldn't work in my case because I'm not using any <base> tags, which were causing the problem there.

This is my table:

class FactTable(tables.Table):
    class Meta:
        model = Fact
        template_name = 'django_tables2/bootstrap.html'
        exclude = ('id',)

This is my view:

def results(request, fields):

     table = FactTable(Fact.objects.filter(category__category=fields['category'],
                                          fact_name=fields['fact'],
                                          time_year__year__range=(startyear, endyear)))

     RequestConfig(request).configure(table)
     return render(request, 'main/results.html', {'table': table})

My urls:

 urlpatterns = [
     url(r'^$', views.index, name='index'),
     url(r'^results/', views.results, name='results'),
 ]

And the template

 {% load render_table from django_tables2 %}
 <!DOCTYPE html>
 <html lang="en">
 <head>
     <meta charset="UTF-8">
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
     <title>Results</title>
 </head>
 <body>
     {% render_table table %}
 </body>
 </html>

Many thanks in advance for any help!

Jieter
  • 4,101
  • 1
  • 19
  • 31
Oleksandr K
  • 119
  • 1
  • 10
  • Ok read this --->>> https://django-tables2.readthedocs.io/en/latest/pages/filtering.html#filtering and ------>>>> https://django-tables2.readthedocs.io/en/latest/pages/column-headers-and-footers.html#column-headers-and-footers and this ----->>>> https://django-tables2.readthedocs.io/en/latest/pages/pinned-rows.html#pinned-rows – Mbambadev Sep 20 '18 at 14:26

0 Answers0