Search code examples
pythondjangodjango-tables2

When used django_tables2, it told me TemplateDoesNotExist


urls.py

urlpatterns = [

    url(r'^admin/', admin.site.urls),
    url(r'^$', views.people),
]

views.py

def people(request):

    return render(request, 'people.html', {'people': models.Person.objects.all()})

models.py

class Person(models.Model):

    name = CharField(verbose_name="full name", max_length=10)

people.html

{% load render_table from django_tables2 %}
{% load static %}

{% render_table people %}

When I run it, it told me TemplateDoesNotExist at /django_tables2/table.html, I don't understand why.


Solution

  • First, make sure that django_tables2 is included in your INSTALLED_APPS setting.

    Then, make sure that you have APP_DIRS set to True in your TEMPLATES setting.

    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [...],
            'APP_DIRS': True,
            ...
        },
    ]