Django-MPTT, how to

2019-06-23 03:03发布

问题:

Hey, I have just installed the django-mptt lib, but i don't know how to get it to work :(

I have added

from mptt.models import MPTTModel

class Category(MPTTModel):
    slug = models.SlugField(max_length=200, unique=True)
    name = models.CharField(max_length=100)
    parent = models.ForeignKey('self', blank=True, null=True, related_name='child')

It that works fine

-

But when i go to the Django Admin page of my site i got an error:

TemplateDoesNotExist at /admin/search/category/

admin/mptt_change_list.html

回答1:

Googling this error message brought me here.

In my case solution was to simply add 'mptt' to INSTALLED_APPS for template loader to find admin/mptt_change_list.html



回答2:

pip install django-mptt --upgrade solved the problem for me. There is a closed issue about this here: https://github.com/django-mptt/django-mptt/issues/23



回答3:

Had the same problem whith mptt installed with easy_install. Had to force unzipping:

easy_install --always-unzip django-mptt-0.5.5.tar.gz



回答4:

I managed to get the same error (0.5.5). You also have to add 'django_mptt_admin' to INSTALLED_APPS.

Phillip.



回答5:

In settings.py from Django 1.4, TEMPLATE_LOADERS had eggs.Loader commented out by default.

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
  # 'django.template.loaders.eggs.Loader',
)

Uncommenting eggs.Loader allowed the four admin templates stored in

python/virtenv/lib/python2.7/site-packages/django_mptt-0.7.4-py2.7.egg

to be found.