问题描述
因此,我刚刚设置了我的Digital Ocean Drop(服务器),并一直在努力使该站点正常工作,但是我遇到了一个又一个错误。我终于找到了加载登录页面的网站(应该执行的操作),但是登录时出现了一个错误,提示您无法加载Argon2 Pass Hasher。我真的不知道问题出在哪里,因为在开发过程中一切正常。
这是错误:
/ accounts / login /
中的
ValueError无法加载'Argon2PasswordHasher'算法库:没有名为argon2
这是我的设置:
django_project项目的Django设置
由django-admin startproject使用Django 1.8.7生成。
有关此文件的更多信息,请参见
https://docs.djangoproject.com/zh-CN/1.8/topics/settings/
有关设置及其值的完整列表,请参见
https://docs.djangoproject。 com / en / 1.8 / ref / settings /
#在项目内部构建路径,如下所示:os.path.join(BASE_DIR,...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__ file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR,'templates ')
MEDIA_DIR = os.path.join(BASE_DI R,媒体)
#快速启动开发设置-不适合生产
#参见https://docs.djangoproject.com/zh/1.8/howto/部署/清单/
#安全警告:请将生产中使用的密钥保密!
SECRET_KEY ='h& *(yq942_a ^ pa + ty& wh(bl9s4d#z ^ * _ 6cmeb#5& 49jb ^ r $&!f'
#安全警告:唐
DEBUG =真
ALLOWED_HOSTS = []
#应用程序定义
INSTALLED_APPS =(
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib。会话,
django.contrib.messages,
django.contrib.staticfiles,
django.contrib.sites,
用户 ,
'feed',
'blog',
'allauth',
'allauth.account',
'allauth.socialaccount',
)
MIDDLEWARE_CLASSES =(
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
' django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middlewar e.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF ='django_project.urls'
模板= [
{
'BACKEND':'django.template.backends。 django.DjangoTemplates',
'DIRS':[],
'APP_DIRS':真,
'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 ='django_project.wsgi.application'
#数据库
#https://docs.djangoproject.com/en/1.8/ref/settings/#dat abases
DATABASES = {
'默认':{
'ENGINE':'django.db.backends.sqlite3',
'NAME':os.path .join(BASE_DIR,'db.sqlite3'),
}
}
#密码验证
#https://docs.djangoproject.com/zh/ 1.11 / ref / settings /#auth-password-validators
PASSWORD_HASHERS = [
'django.contrib.auth.hashers.Argon2PasswordHasher',
'django.contrib.auth。 hashers.BCryptSHA256PasswordHasher',
'django.contrib.auth.hashers.BCryptPasswordHasher',
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
'django.contrib.auth.hashers。 PBKDF2SHA1PasswordHasher',
]
#国际化
#https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE ='en-us'
TIME_ZONE ='UTC'
USE_I18N =真实
USE_L10N =真实
USE_TZ =真
SITE_ID = 1
#静态文件(CSS,JavaScript,图像)
#https:// docs。 dj angoproject.com/zh-CN/1.8/howto/static-files/
STATIC_URL ='/ static /'
STATIC_ROOT ='/ static /'
STATIC_DIR = os.path。 join(BASE_DIR,'static')
STATICFILES_DIRS = [
STATIC_DIR,
]
#MEDIA
MEDIA_ROOT = MEDIA_DIR
MEDIA_URL ='/ media /'
LOGIN_URL ='/ user_login'
#设置
ACCOUNT_AUTHENTICATION_METHOD ='username_email'
ACCOUNT_USERNAME_REQUIRED =真
ACCOUNT_UNIQUE_USERNAME =真
ACCOUNT_SIGNUP_EMAIL_ENTER_TWICE =假
ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE =真
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 3
ACLOG_TEMPS = 3
ACLOG_SIGN_LOG_TEMPS = 3 =真
ACCOUNT_SESSION_REMEMBER =无
ACCOUNT_ADAPTER ='allauth.account.adapter.DefaultAccountAdapter'
ACCOUNT_UNIQUE_EMAIL =真
#SOCIALACCOUNT_AUTO_SIGNUP =真
#SOCIALACCOUNT_EMAIL_REQUIRED ='ACCOUNT_EMAIL_REQUIRED'
#SOCIALACCOUNT_QUERY_EMAIL ='ACCOUNT_EMAIL_REQUIRED'
ACCOUNT_EMAIL_REQUIRED =真实
ACCOUNT_EMAIL_CONFIRMATION_HMAC =真
ACCOUNT_EMAIL_VERIFICATION ='none'
#ACCOUNT_EMAIL_VERIFICATION ='可选'
b ACCOUNT_EMAIL_VERIFICATION ='强制性'
EMAIL_BACKEND ='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST ='smtp.sendgrid.com'
EMAIL_HOST_PASSWORD ='密码'
EMAIL_HOST_USER ='用户名'
EMAIL_PORT = 587
EMAIL_USE_TLS =真
DEFAULT_FROM_EMAIL ='[email protected]'
#像这样在项目内部构建路径:os.path.join(BASE_DIR,...)
#允许所有主机上的Django。此代码段是从
#/ var / lib / digitalocean / allow_hosts.py
import os
import netifaces
#安装的地址在运行时
#这是必要的,因为否则Gunicorn将拒绝连接
def ip_addresses():
ip_list = [] netifaces.interfaces()中接口的
:
addrs = netifaces.ifaddresses(interface)
for x in(netifaces.AF_INET,netifaces.AF_INET6):
如果x in addrs:
ip_list.append(addrs [x] [0] ['addr'])
return ip_list
#发现我们的IP地址
ALLOWED_HOSTS = ip_addresses()
这是回溯:
跟踪切换到复制-粘贴视图
/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py在内部
response = get_response(request).. 。
▶本地变量
/usr/local/lib/python2.7/dist-packages/django/co _legacy_get_response
response = self._get_response(request)...中的re / handlers / base.py ...
▶本地变量
/usr/local/lib/python2.7/dist-packages/ _get_response中的django / core / handlers / base.py
响应= self.process_exception_by_middleware(e,request)...
▶本地变量
/usr/local/lib/python2.7/ _get_response中的dist-packages / django / core / handlers / base.py
响应= wrapper_callback(request,* callback_args,** callback_kwargs)...
▶本地变量
/ usr / local /lib/python2.7/dist-packages/django/views/generic/base.py in view
return self.dispatch(request,* args,** kwargs)...
▶本地变量
/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py in _wrapper
return bound_func(* args,** kwargs)...
▶局部变量
/usr/local/lib/python2.7/dist-packages/django/views/decorators/debug.py insensitive_post_parameters_wrapper
return view(request,* arg s,** kwargs)...
▶本地变量
/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py in bound_func
return func .__ get __(self,type(self))(* args2,** kwargs2)...
▶本地变量
/home/django/django_project/allauth/account/views.py在分派$ b中$ b return super(LoginView,self).dispatch(request,* args,** kwargs)...
▶本地变量
/home/django/django_project/allauth/account/views.py在dispatch
** kwargs)...
▶本地变量
/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py in b $ b返回处理程序(request,* args,** kwargs)...
▶本地变量
/home/django/django_project/allauth/account/views.py在
中form.is_valid():...
▶本地变量
/usr/local/lib/python2.7/dist-packages/django/forms/forms.py in is_valid
return self .is_bound而不是self.errors ...
▶本地变量
/ usr / local / lib / pyt hon2.7 / dist-packages / django / forms / forms.py错误
self.full_clean()...
▶本地变量
/usr/local/lib/python2.7 /dist-packages/django/forms/forms.py in full_clean
self._clean_form()...
▶本地变量
/usr/local/lib/python2.7/dist- _clean_form中的packages / django / forms / forms.py
cleaned_data = self.clean()...
▶本地变量
/home/django/django_project/allauth/account/forms.py在干净的
**凭证中)...
▶本地变量
/home/django/django_project/allauth/account/adapter.py in authenticate
user = authenticate(request = request,** credentials)...
▶本地vars
/home/django/django_project/allauth/compat.py in authenticate
return authenticate(request = request,** credentials)。 ..
▶本地变量
/usr/local/lib/python2.7/dist-packages/django/contrib/auth/__init__.py in authenticate
user = _authenticate_with_backend(backend,backend_path ,要求est,凭据)...
▶本地变量
/usr/local/lib/python2.7/dist-packages/django/contrib/auth/__init__.py in _authenticate_with_backend
返回后端.authenticate(* args,** credentials)...
▶本地变量
/usr/local/lib/python2.7/dist-packages/django/contrib/auth/backends.py
如果user.check_password(password)和self.user_can_authenticate(user):...
▶本地变量
/usr/local/lib/python2.7/dist-packages/django/ contrib / auth / base_user.py in check_password
return check_password(raw_password,self.password,setter)...
▶本地变量
/usr/local/lib/python2.7/dist -packages / django / contrib / auth / hashers.py in check_password
must_update = hasher_changed或preferred.must_update(encoded)...
▶本地变量
/ usr / local / lib / python2 must_update
中的.7 / dist-packages / django / contrib / auth / hashers.py arg2 = self._load_library()...
▶本地变量
/ usr / local / lib / python2.7 / dist-packa _load_library
中的ges / django / contrib / auth / hashers.py(self .__ class __.__ name__,e))...
▶本地变量
请帮忙,这个问题似乎很具体,所以我无法在其中找到很多...
解决方案根据:
这很简单,我只需要运行
pip install django [argon2]
在服务器上,相当于python -m pip install argon2-cffi
。So I have just setup my Digital Ocean droplet (server) and have been working to get this site to work, however I have been coming across error after error. I finally got the site to load the login page (which is what should happen), but when I login I get an error that Argon2 Pass Hasher couldn't load. I really have no idea what the problem is, as everything was working perfectly while in development.
Here is the error:
ValueError at /accounts/login/ Couldn't load 'Argon2PasswordHasher' algorithm library: No module named argon2
Here are my settings:
""" Django settings for django_project project. Generated by 'django-admin startproject' using Django 1.8.7. For more information on this file, see https://docs.djangoproject.com/en/1.8/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.8/ref/settings/ """ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates') MEDIA_DIR = os.path.join(BASE_DIR, 'media') # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'h&*(yq942_a^pa+ty&wh(bl9s4d#z^*_6cmeb#5&49jb^r$&!f' # 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', 'django.contrib.sites', 'users', 'feed', 'blog', 'allauth', 'allauth.account', 'allauth.socialaccount', ) MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware', ) ROOT_URLCONF = 'django_project.urls' 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', ], }, }, ] WSGI_APPLICATION = 'django_project.wsgi.application' # Database # https://docs.djangoproject.com/en/1.8/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.11/ref/settings/#auth-password-validators PASSWORD_HASHERS = [ 'django.contrib.auth.hashers.Argon2PasswordHasher', 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher', 'django.contrib.auth.hashers.BCryptPasswordHasher', 'django.contrib.auth.hashers.PBKDF2PasswordHasher', 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher', ] # Internationalization # https://docs.djangoproject.com/en/1.8/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True SITE_ID = 1 # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.8/howto/static-files/ STATIC_URL = '/static/' STATIC_ROOT = '/static/' STATIC_DIR = os.path.join(BASE_DIR,'static') STATICFILES_DIRS = [ STATIC_DIR, ] #MEDIA MEDIA_ROOT = MEDIA_DIR MEDIA_URL = '/media/' LOGIN_URL = '/user_login' # settings ACCOUNT_AUTHENTICATION_METHOD = 'username_email' ACCOUNT_USERNAME_REQUIRED = True ACCOUNT_UNIQUE_USERNAME =True ACCOUNT_SIGNUP_EMAIL_ENTER_TWICE =False ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE =True ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS =3 ACCOUNT_LOGIN_ATTEMPTS_LIMIT = 5 ACCOUNT_LOGOUT_ON_PASSWORD_CHANGE =True ACCOUNT_SESSION_REMEMBER =None ACCOUNT_ADAPTER ='allauth.account.adapter.DefaultAccountAdapter' ACCOUNT_UNIQUE_EMAIL =True # SOCIALACCOUNT_AUTO_SIGNUP =True # SOCIALACCOUNT_EMAIL_REQUIRED ='ACCOUNT_EMAIL_REQUIRED' # SOCIALACCOUNT_QUERY_EMAIL ='ACCOUNT_EMAIL_REQUIRED' ACCOUNT_EMAIL_REQUIRED = True ACCOUNT_EMAIL_CONFIRMATION_HMAC =True ACCOUNT_EMAIL_VERIFICATION = 'none' #ACCOUNT_EMAIL_VERIFICATION = 'optional' #ACCOUNT_EMAIL_VERIFICATION = 'mandatory' EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.sendgrid.com' EMAIL_HOST_PASSWORD = 'password' EMAIL_HOST_USER = 'username' EMAIL_PORT = 587 EMAIL_USE_TLS = True DEFAULT_FROM_EMAIL = '[email protected]' # Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Allow Django from all hosts. This snippet is installed from # /var/lib/digitalocean/allow_hosts.py import os import netifaces # Find out what the IP addresses are at run time # This is necessary because otherwise Gunicorn will reject the connections def ip_addresses(): ip_list = [] for interface in netifaces.interfaces(): addrs = netifaces.ifaddresses(interface) for x in (netifaces.AF_INET, netifaces.AF_INET6): if x in addrs: ip_list.append(addrs[x][0]['addr']) return ip_list # Discover our IP address ALLOWED_HOSTS = ip_addresses()
Here is the traceback:
Traceback Switch to copy-and-paste view /usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py in inner response = get_response(request) ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py in _legacy_get_response response = self._get_response(request) ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py in _get_response response = self.process_exception_by_middleware(e, request) ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/views/generic/base.py in view return self.dispatch(request, *args, **kwargs) ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/utils/decorators.py in _wrapper return bound_func(*args, **kwargs) ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/views/decorators/debug.py in sensitive_post_parameters_wrapper return view(request, *args, **kwargs) ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/utils/decorators.py in bound_func return func.__get__(self, type(self))(*args2, **kwargs2) ... ▶ Local vars /home/django/django_project/allauth/account/views.py in dispatch return super(LoginView, self).dispatch(request, *args, **kwargs) ... ▶ Local vars /home/django/django_project/allauth/account/views.py in dispatch **kwargs) ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/views/generic/base.py in dispatch return handler(request, *args, **kwargs) ... ▶ Local vars /home/django/django_project/allauth/account/views.py in post if form.is_valid(): ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/forms/forms.py in is_valid return self.is_bound and not self.errors ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/forms/forms.py in errors self.full_clean() ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/forms/forms.py in full_clean self._clean_form() ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/forms/forms.py in _clean_form cleaned_data = self.clean() ... ▶ Local vars /home/django/django_project/allauth/account/forms.py in clean **credentials) ... ▶ Local vars /home/django/django_project/allauth/account/adapter.py in authenticate user = authenticate(request=request, **credentials) ... ▶ Local vars /home/django/django_project/allauth/compat.py in authenticate return authenticate(request=request, **credentials) ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/contrib/auth/__init__.py in authenticate user = _authenticate_with_backend(backend, backend_path, request, credentials) ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/contrib/auth/__init__.py in _authenticate_with_backend return backend.authenticate(*args, **credentials) ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/contrib/auth/backends.py in authenticate if user.check_password(password) and self.user_can_authenticate(user): ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/contrib/auth/base_user.py in check_password return check_password(raw_password, self.password, setter) ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/contrib/auth/hashers.py in check_password must_update = hasher_changed or preferred.must_update(encoded) ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/contrib/auth/hashers.py in must_update argon2 = self._load_library() ... ▶ Local vars /usr/local/lib/python2.7/dist-packages/django/contrib/auth/hashers.py in _load_library (self.__class__.__name__, e)) ... ▶ Local vars
Please help, this issue seems to be rather specific so I haven't been able to find very much on it...
解决方案According to the documentation:
It was simple, I just had to run
pip install django[argon2]
on the server, which is equivalent topython -m pip install argon2-cffi
.这篇关于实时生产中argon2 hasher的Django问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!