Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Raises ImproperlyConfigured When Trying to Create A Menu by django-admin-tools

Tags:

python

django

I successfully configured django-admin-tools for using. I tried to create a custom menu as told in documentation as below:

python3 manage.py custommenu

However, this raised an ImproperlyConfugured error below, saying:

django.core.exceptions.ImproperlyConfigured: app_dirs must not be set when loaders is defined.

I looked at the directory, menu.py is successfully created, yet the content is empty in opposition to the documentation.

My confituration of TEMPLATES variable is below:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
                'admin_tools.template_loaders.Loader',
            ],
            'loaders': [
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
                'admin_tools.template_loaders.Loader',
            ],
        },
    },
]

Does that mean I need to install django-admin-tools before creating any app?

Enviroment

  • python3
  • django 1.8.7
like image 491
Eray Erdin Avatar asked Jan 10 '16 18:01

Eray Erdin


2 Answers

Remove the 'APP_DIRS': True, line.

like image 65
Alex Morozov Avatar answered Sep 19 '22 14:09

Alex Morozov


If you wanted to know why you'd need to remove 'APP_DIRS': True, to make it work then I would suggest you have a read in the docs - https://docs.djangoproject.com/en/dev/ref/templates/api/#django.template.loaders.app_directories.Loader
Note: Please use the corresponding docs for your django version.

In general:
APP_DIRS and the option loaders does not work together, so you're left with two options:

  1. remove loaders from OPTIONS
  2. remove APP_DIRS

Re question:
Since Erdin wanted to use 'admin_tools.template_loaders.Loader' he had to remove APP_DIRS. However, you might tumble across this question for a different reason and so considering option number 1 might be worthwhile.

like image 23
slajma Avatar answered Sep 19 '22 14:09

slajma