本文整理匯總了Python中django.conf.settings.PASSWORD_HASHERS屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.PASSWORD_HASHERS屬性的具體用法?Python settings.PASSWORD_HASHERS怎麽用?Python settings.PASSWORD_HASHERS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.conf.settings
的用法示例。
在下文中一共展示了settings.PASSWORD_HASHERS屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_hasher
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import PASSWORD_HASHERS [as 別名]
def get_hasher(algorithm='default'):
"""
Returns an instance of a loaded password hasher.
If algorithm is 'default', the default hasher will be returned.
This function will also lazy import hashers specified in your
settings file if needed.
"""
if hasattr(algorithm, 'algorithm'):
return algorithm
elif algorithm == 'default':
return get_hashers()[0]
else:
hashers = get_hashers_by_algorithm()
try:
return hashers[algorithm]
except KeyError:
raise ValueError("Unknown password hashing algorithm '%s'. "
"Did you specify it in the PASSWORD_HASHERS "
"setting?" % algorithm)
示例2: get_hasher
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import PASSWORD_HASHERS [as 別名]
def get_hasher(algorithm='default'):
"""
Return an instance of a loaded password hasher.
If algorithm is 'default', return the default hasher. Lazily import hashers
specified in the project's settings file if needed.
"""
if hasattr(algorithm, 'algorithm'):
return algorithm
elif algorithm == 'default':
return get_hashers()[0]
else:
hashers = get_hashers_by_algorithm()
try:
return hashers[algorithm]
except KeyError:
raise ValueError("Unknown password hashing algorithm '%s'. "
"Did you specify it in the PASSWORD_HASHERS "
"setting?" % algorithm)
示例3: shared_static_pages
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import PASSWORD_HASHERS [as 別名]
def shared_static_pages(request, page):
from django.utils.module_loading import import_string
from django.contrib.humanize.templatetags.humanize import intcomma
password_hasher = import_string(settings.PASSWORD_HASHERS[0])()
password_hash_method = password_hasher.algorithm.upper().replace("_", " ") \
+ " (" + intcomma(password_hasher.iterations) + " iterations)"
return render(request,
page + ".html", {
"base_template": "base.html",
"SITE_ROOT_URL": request.build_absolute_uri("/"),
"password_hash_method": password_hash_method,
# "project_form": ProjectForm(request.user),
"project_form": None,
})
# SINGLE SIGN ON
示例4: get_hashers
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import PASSWORD_HASHERS [as 別名]
def get_hashers():
hashers = []
for hasher_path in settings.PASSWORD_HASHERS:
hasher_cls = import_string(hasher_path)
hasher = hasher_cls()
if not getattr(hasher, 'algorithm'):
raise ImproperlyConfigured("hasher doesn't specify an "
"algorithm name: %s" % hasher_path)
hashers.append(hasher)
return hashers
示例5: reset_hashers
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import PASSWORD_HASHERS [as 別名]
def reset_hashers(**kwargs):
if kwargs['setting'] == 'PASSWORD_HASHERS':
get_hashers.cache_clear()
get_hashers_by_algorithm.cache_clear()
示例6: __init__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import PASSWORD_HASHERS [as 別名]
def __init__(self, *args, **kwargs):
# For speed:
settings.PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher",)
# Send emails synchronously
settings.BLOCKING_EMAILS = True
super(CustomRunner, self).__init__(*args, **kwargs)
示例7: pytest_configure
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import PASSWORD_HASHERS [as 別名]
def pytest_configure():
settings.DEBUG = False
# If you have any test specific settings, you can declare them here,
# e.g.
# settings.PASSWORD_HASHERS = (
# 'django.contrib.auth.hashers.MD5PasswordHasher',
# )
django.setup()
# Note: In Django =< 1.6 you'll need to run this instead
# settings.configure()
示例8: pytest_configure
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import PASSWORD_HASHERS [as 別名]
def pytest_configure():
settings.DEBUG = False
# If you have any test specific settings, you can declare them here,
# e.g.
# settings.PASSWORD_HASHERS = (
# 'django.contrib.auth.hashers.MD5PasswordHasher',
# )
django.setup()
# Give django database access to all tests.
# The alternative is to mark just the test functions that need DB access with:
# @pytest.mark.django_db