2017-08-03 51 views
0

我試圖用django-admin-tools自定義管理界面。ImportError:沒有名爲菜單的模塊

我下面https://django-admin-tools.readthedocs.io/en/latest/customization.html

menu.py已經成功地與python manage.py custommenu在我的項目目錄中創建。

我有那麼重命名爲Mymenu.py

當我添加ADMIN_TOOLS_MENU = 'project_name.Mymenu.CustomMenu'settings.py,指示我得到follwoing錯誤:ImportError: No module named menu

我settings.py

import os 

# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 



DEBUG = True 

ALLOWED_HOSTS = [] 


# Application definition 

INSTALLED_APPS = [ 
    'admin_tools', 
    'admin_tools.theming', 
    'admin_tools.menu', 
    'admin_tools.dashboard', 
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'admin_platform', 
    'colorful', 
] 

MIDDLEWARE = [ 
    'django.middleware.security.SecurityMiddleware', 
    'django.contrib.sessions.middleware.SessionMiddleware', 
    'django.middleware.common.CommonMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    'django.contrib.messages.middleware.MessageMiddleware', 
    'django.middleware.clickjacking.XFrameOptionsMiddleware', 
] 


TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [os.path.join(BASE_DIR, 'templates')], 
     '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', 
      ], 
      'loaders': [ 'admin_tools.template_loaders.Loader', 
         ('django.template.loaders.cached.Loader', [ 
            'django.template.loaders.filesystem.Loader', 
            'django.template.loaders.app_directories.Loader', 
            ]), 

         ] 
     }, 
    }, 
] 


DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.sqlite3', 
     'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 
    } 
} 



# Static files (CSS, JavaScript, Images) 
# https://docs.djangoproject.com/en/1.11/howto/static-files/ 

STATIC_URL = '/static/' 
STATIC_ROOT = os.path.join(BASE_DIR,'static') 
STATICFILES_FINDERS = ['django.contrib.staticfiles.finders.AppDirectoriesFinder'] 

ADMIN_TOOLS_MENU = 'myProject.Mymenu.CustomMenu' 
+0

是這種情況下,您的installed_apps中的應用程序? – allcaps

+0

您是否導入模塊?無論如何,請添加您的代碼 – Paddy

+0

您使用命令創建應用程序 python manage.py startapp custommenu 對不對? –

回答

0

我假設您使用以下命令創建了該應用程序,

python manage.py startapp custommenu 

,然後改名爲views.py到Mymenu.py

在你需要在你安裝的應用程序編寫custommenu而不是Mymenu

+0

不,我正在關注https://django-admin-tools.readthedocs.io/en/latest/customization.html –

+0

在這種情況下,我認爲您不需要將其添加到您已安裝的應用程序中。您需要添加django管理工具,請檢查此https://django-admin-tools.readthedocs.io/en/latest/configuration.html –

+0

是的,我知道,沒有必要添加它,我只添加它作爲解決錯誤的嘗試,我更新了我的問題 –

0

我解決它通過更換ADMIN_TOOLS_MENU = 'project_name.Mymenu.CustomMenu'只需ADMIN_TOOLS_MENU = 'Mymenu.CustomMenu'

相關問題