Django-MPTT, how to

情到浓时终转凉″ 提交于 2019-12-10 14:16:21

问题


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.



来源:https://stackoverflow.com/questions/5350216/django-mptt-how-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!