Django的xadmin运行错误

时间:2018-08-30 16:28:25

标签: python django

我使用xadmin管理项目,并且我希望将语言从英语更改为中文,因此我向apps.py添加了“ verbose_name ='用户信息'”,并添加了“ default_app_config ='users.apps”。 UsersConfigure“” to users。 init .py。最后,开始运行是错误的。 这是我的users.apps.py文件:

from django.apps import AppConfig


class UsersConfig(AppConfig):
    name = 'users'
    verbose_name = '用户信息'

这是我的settings.py文件:

   """
Django settings for MuKeOnline project.

Generated by 'django-admin startproject' using Django 1.11.11.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""

import os
import sys

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


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'f*@!o)%f)0cs$*&154i-w5(f7jpjtcc_nc99(h22b-_xe$qt4w'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'xadmin',
'crispy_forms',
'reversion',
'users.apps.UsersConfig',
'course',
'organization',
'operation',
]

# 使用自定义用户表
AUTH_USER_MODEL = 'users.UserProfile'

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',
]

ROOT_URLCONF = 'MuKeOnline.urls'

TEMPLATES = [
 {
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, 'templates')]
    ,
    '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',
        ],
    },
  },
 ]

 WSGI_APPLICATION = 'MuKeOnline.wsgi.application'


 # Database
 # https://docs.djangoproject.com/en/1.11/ref/settings/#databases

 DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'muke_app',
    'USER':'root',
    'PASSWORD':'mysql',
    'HOST':'127.0.0.1'
}
}


# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators 


 AUTH_PASSWORD_VALIDATORS = [
  {
    'NAME': 

'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
    'NAME': 
 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
     'NAME': 
 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
     'NAME': 
 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
 ]


 # Internationalization

 # https://docs.djangoproject.com/en/1.11/topics/i18n/

 LANGUAGE_CODE = 'zh-hans'

 TIME_ZONE = 'Asia/Shanghai'

 USE_I18N = True

 USE_L10N = True

 USE_TZ = False


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

 STATIC_URL = '/static/'

这是错误:

Unhandled exception in thread started by <function check_errors. 
<locals>.wrapper at 0x7f62a63a4400>
Traceback (most recent call last):
File "/home/python/.virtualenvs/django_py3_1.11/lib/python3.5/site- 
packages/django/apps/config.py", line 140, in create
app_name = cls.name
AttributeError: type object 'AppConfig' has no attribute 'name'

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/python/.virtualenvs/django_py3_1.11/lib/python3.5/site- 
 packages/django/utils/autoreload.py", line 228, in wrapper
 fn(*args, **kwargs)
 File "/home/python/.virtualenvs/django_py3_1.11/lib/python3.5/site- 
packages/django/core/management/commands/runserver.py", line 116, in 
inner_run
 autoreload.raise_last_exception()
File "/home/python/.virtualenvs/django_py3_1.11/lib/python3.5/site- 
packages/django/utils/autoreload.py", line 251, in raise_last_exception
six.reraise(*_exception)
File "/home/python/.virtualenvs/django_py3_1.11/lib/python3.5/site- 
packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/python/.virtualenvs/django_py3_1.11/lib/python3.5/site- 
packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/home/python/.virtualenvs/django_py3_1.11/lib/python3.5/site- 
packages/django/__init__.py", line 27, in setup
 apps.populate(settings.INSTALLED_APPS)
File "/home/python/.virtualenvs/django_py3_1.11/lib/python3.5/site- 
packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/home/python/.virtualenvs/django_py3_1.11/lib/python3.5/site- 
packages/django/apps/config.py", line 143, in create
"'%s' must supply a name attribute." % entry)
django.core.exceptions.ImproperlyConfigured: 'users.apps.AppConfig' must 
supply a name attribute.

这是我第一个要问的问题,我不擅长使用它。谢谢您的原谅,谢谢您的回答。

0 个答案:

没有答案