[Fixed]-Django tables 'module' object has no attribute 'index'

1👍

Uncomment the index method as Joel has stated and then render an html page as you have done in the people method, passing the table data as well.

https://docs.djangoproject.com/en/1.9/intro/tutorial03/

About 3/4 down the page (slightly modified to suit your example):

def index(request):
    table_object = ......
    template = loader.get_template('correct_page_here')
    context = {
        'table_obj': table_object,
}
    return HttpResponse(template.render(context, request))

In the corresponding html page add the appropriate tags to render the table

https://django-tables2.readthedocs.org/en/latest/pages/template-tags.html

I changed your model files to this:

from __future__ import unicode_literals

from django.db import models

data = [
    {"name": "Me!"},
    {"name": "Myself!"},
]

# Create your models here.
class Person(models.Model):
    name = models.CharField(verbose_name="full name", max_length = 20)

After changing the model file make sure you run

python manage.py makemigrations && python manage.py migrate

Your tables/urls.py file to:

from django.conf.urls import url
from . import views

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

Your views.py file to:

from django.shortcuts import render
from django.http import HttpResponse
from models import Person 


def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")


def people(request):
    return render(request, "people.html", {"people": Person.objects.all()})
    table = Person(data)

The installed apps in IMed/IMed/settings.py to:

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_tables2',
    'IMed',
    'tables',
]

Now if you run the server and go here:

http://127.0.0.1:8000/tables/people/

The people view will work and you can copy the same process in index as you have in people.

👤BenJ

Leave a comment