2016-11-08 40 views
2

我想更改django-allauth中的ACCOUNT_PASSWORD_MIN_LENGTH。我在settings.py中嘗試了ACCOUNT_PASSWORD_MIN_LENGTH = 5並且它不工作,Django仍然說我需要輸入8個字符,就像默認情況下一樣。如何在django-allauth中爲用戶密碼設置最少字符數

這裏是我的settings.py文件:

# Application definition 

INSTALLED_APPS = [ 
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'blog', 
    'taggit', 
    'django_summernote', 
    'django.contrib.sites', 
    'allauth', 
    'allauth.account', 
    'allauth.socialaccount', 
    'user_account', 
    'widget_tweaks', 

] 

SITE_ID = 1 

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 = 'project_blog.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 = 'project_blog.wsgi.application' 


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

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


# Password validation 
# https://docs.djangoproject.com/en/1.10/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', 
    }, 
] 

# Django-allauth 
AUTHENTICATION_BACKENDS = (
    # Needed to login by username in Django admin, regardless of `allauth` 
    'django.contrib.auth.backends.ModelBackend', 

    # `allauth` specific authentication methods, such as login by e-mail 
    'allauth.account.auth_backends.AuthenticationBackend', 
) 

# Internationalization 
# https://docs.djangoproject.com/en/1.10/topics/i18n/ 

LANGUAGE_CODE = 'en-us' 

TIME_ZONE = 'UTC' 

USE_I18N = True 

USE_L10N = True 

USE_TZ = True 


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

STATIC_URL = '/static/' 

STATICFILES_DIRS = [ 
    os.path.join(BASE_DIR, 'static'), 
    #'/var/www/static/', 
] 

STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static_cdn') 

MEDIA_URL = '/media/' 
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'media_cdn') 


SUMMERNOTE_CONFIG = { 
    # Using SummernoteWidget - iframe mode 
    'iframe': True, # or set False to use SummernoteInplaceWidget - no iframe mode 

    # Using Summernote Air-mode 
    'airMode': False, 

    # Use native HTML tags (`<b>`, `<i>`, ...) instead of style attributes 
    # (Firefox, Chrome only) 
    'styleWithTags': True, 

    # Set text direction : 'left to right' is default. 
    'direction': 'ltr', 

    # Change editor size 
    'width': '100%', 
    'height': '480', 

    # Authentication required 
    'attachment_require_authentication': False, 
} 

EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend' 

# Custom allauth settings 
# Use email as the primary identifier 
ACCOUNT_AUTHENTICATION_METHOD = 'email' 
ACCOUNT_EMAIL_REQUIRED = True 
# Make email verification mandatory to avoid junk email accounts 
ACCOUNT_EMAIL_VERIFICATION = 'mandatory' 
# Eliminate need to provide username, as it's a very old practice 
ACCOUNT_USERNAME_REQUIRED = False 
# Minimum password characters 
ACCOUNT_PASSWORD_MIN_LENGTH = 5 

回答

3

django docs,你需要同時指定OPTIONS字典,內置在Django密碼驗證,這樣的:

相關問題