Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8173709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:15:14+00:00 2026-06-06T22:15:14+00:00

can’t get sorting working for a django-tables2 table. class MyModel(models.Model): pid = models.AutoField(‘id’,primary_key =

  • 0

can’t get sorting working for a django-tables2 table.

class MyModel(models.Model):
    pid = models.AutoField('id',primary_key = True)
    name = models.CharField(max_length = 255,
                            help_text='The name')
def show_mymodels(request):
    """ the view """
    table = MyModelTable(MyModel.objects.all())
    return render(request,'mymodel.html',{'table':table})

class MyModelTable(tables.Table):
    class Meta:
        model = MyModel
        orderable = True

And mymodel.html looks as follows:

{% load render_table from django_tables2 %}
{% render_table table %}

This renders the table correct but nothing happens when clicking the columns in the browser. Other then the urld change http://127.0.0.1:8000/show_mymodel –> http://127.0.0.1:8000/show_mymodel?sort=name

What is it that I’m doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:15:18+00:00Added an answer on June 6, 2026 at 10:15 pm

    You need a RequestConfig object as explained in the tutorial:

    Using RequestConfig automatically pulls values from request.GET and updates the table accordingly. This enables data ordering and pagination.


    from django_tables2 import RequestConfig
    
    def show_mymodels(request):
        table = MyModelTable(MyModel.objects.all())
        RequestConfig(request).configure(table)
        return render(request, 'mymodel.html', {'table': table})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can any one tell, how to get the result of LINQ query contains group
Can I register a .Net COM class with the SingleUse -flag? The reason I
Can some one Guide me to work with these things... What is Model popup
Can't seem to get the Back Button to appear in a UINavigationController flow. I
Can i get the source code for a WAMP stack installer somewhere? Any help
Can you set the internal [[Class]] property of an ECMAScript object?
Can't get Youtube's homepage, or any other youtube.com prefixed URL to load in an
Can anyone let me know how can we change the value of kendo combobox
Can I order my users in the database, so I don't have to say

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.