3

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.

dlmeetei
  • 9,905
  • 3
  • 31
  • 38
jianbo jia
  • 45
  • 6
  • The full error message should give more information, including where Django searched for the template. It would be useful to see your `TEMPLATES` setting as well. – Alasdair Aug 18 '17 at 09:07

1 Answers1

0

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,
        ...
    },
]
Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] – jianbo jia Aug 18 '17 at 11:31
  • Make sure that `django_tables2` is included in your `INSTALLED_APPS`. – Alasdair Aug 18 '17 at 11:44
  • I don't have any other suggestions. As I suggested before, the full error message might show want the problem is (please edit your original question instead of pasting code in the comments). – Alasdair Aug 18 '17 at 11:59
  • TemplateDoesNotExist at / django_tables2/table.html Request Method: GET Request URL: http://127.0.0.1:8000/ Django Version: 1.11.2 Exception Type: TemplateDoesNotExist Exception Value: django_tables2/table.html Exception Location: C:\Python27\lib\site-packages\django-1.11.2-py2.7.egg\django\template\loader.py in get_template, line 25 – jianbo jia Aug 18 '17 at 12:03
  • In template C:\Users\XJ\Desktop\123\untitled\templates\people.html, error at line 10 – jianbo jia Aug 18 '17 at 12:04
  • 1 {# tutorial/templates/people.html #} 2 {% load render_table from django_tables2 %} 3 {% load static %} 4 5 6 7 8 9 10 {% render_table people %} 11 12 – jianbo jia Aug 18 '17 at 12:05
  • As I said, please don't post code in the comments. Edit your original question. – Alasdair Aug 18 '17 at 12:31
  • Thank U very much ,I want to know if I should setup STATICFILES_DIRS[ ] and TEMPLATES[{''DIRS[ ]}], when I use it – jianbo jia Aug 21 '17 at 02:59
  • Setting `STATICFILES_DIRS` isn't going to help fix a missing template. The template should be in the `django_tables2` app dir, so you shouldn't have to set `DIRS` to make it work. – Alasdair Aug 21 '17 at 06:47
  • If you have installed django tables 2 as an egg (not recommended), you'll have to either copy the missing template into one of your template directories (and set `DIRS`), or enable the egg loader. – Alasdair Aug 21 '17 at 06:57
  • yes, I have used pip install django_tables2 and also downloaded it from github to setup, when I checked "C:\Python27\Lib\site-packages", I can see "django_tables2-1.10.0-py2.7.egg", I want to know if this installed has some problems? – jianbo jia Aug 21 '17 at 07:55
  • I copy out "django_tables2" form "django_tables2-1.10.0-py2.7.egg" to site-packages, it worked,but it can't load Css, is this have some problems? – jianbo jia Aug 21 '17 at 08:38
  • "It can't load Css" isn't enough information for me to help you. – Alasdair Aug 21 '17 at 08:56
  • thank you all the same ,I will try it and find the problems – jianbo jia Aug 21 '17 at 09:09