我尝试使用django-admin-tools自定义管理界面。
我跟随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
时,如上所示,我收到了以下错误: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 :(得分:1)
我假设您使用以下命令
创建了应用程序python manage.py startapp custommenu
然后将views.py重命名为Mymenu.py
在这种情况下,您需要在已安装的应用中编写custommenu
而不是Mymenu
答案 1 :(得分:1)
我通过简单地用ADMIN_TOOLS_MENU = 'project_name.Mymenu.CustomMenu'
ADMIN_TOOLS_MENU = 'Mymenu.CustomMenu'
来解决这个问题