Django-MPTT, how to

2019-06-23 02:56发布

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

5条回答
祖国的老花朵
2楼-- · 2019-06-23 03:01

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

Phillip.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-06-23 03:02

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

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-06-23 03:12

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.

查看更多
疯言疯语
5楼-- · 2019-06-23 03:17

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

查看更多
Viruses.
6楼-- · 2019-06-23 03:27

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

查看更多
登录 后发表回答