本文整理匯總了Python中django.conf.settings.SESSION_ENGINE屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.SESSION_ENGINE屬性的具體用法?Python settings.SESSION_ENGINE怎麽用?Python settings.SESSION_ENGINE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.conf.settings
的用法示例。
在下文中一共展示了settings.SESSION_ENGINE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: check
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def check(cls, **kwargs):
"""
We use .session_key and CSRF_COOKIE above: check that they will be there, and fail fast if not.
"""
errors = super().check(**kwargs)
# Ensure we are using the database session store. (Other SessionStores may also have .session_key?)
engine = import_module(settings.SESSION_ENGINE)
store = engine.SessionStore
if not issubclass(store, DatabaseSessionStore):
errors.append(Error(
"Quiz logging uses request.session.session_key, which likely implies "
"SESSION_ENGINE = 'django.contrib.sessions.backends.db' in settings."
))
if 'django.middleware.csrf.CsrfViewMiddleware' not in settings.MIDDLEWARE:
errors.append(Error(
"CsrfViewMiddleware is not enabled in settings: quiz logging uses CSRF_COOKIE and will fail without "
"CSRF checking enabled. Also it should be enabled in general."
))
return errors
示例2: logout
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def logout(self):
"""
Removes the authenticated user's cookies and session object.
Causes the authenticated user to be logged out.
"""
from django.contrib.auth import get_user, logout
request = HttpRequest()
engine = import_module(settings.SESSION_ENGINE)
if self.session:
request.session = self.session
request.user = get_user(request)
else:
request.session = engine.SessionStore()
logout(request)
self.cookies = SimpleCookie()
示例3: simulate_login
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def simulate_login(username, password, headers=None):
rf = RequestFactory()
request = rf.request(**headers)
engine = import_module(settings.SESSION_ENGINE)
request.session = engine.SessionStore()
# TODO remove when we don't support Django 1.10 anymore
# request passed in to authenticate only after Django 1.10
# Also the middleware saving the request to thread local can be dropped
try:
user = authenticate(request, username=username, password=password)
except TypeError:
middleware.thread_data.request = request
user = authenticate(username=username, password=password)
if user:
login(request, user)
示例4: establish_session
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def establish_session(original_function):
'''
Simulate establishing a session.
Adapted from https://code.djangoproject.com/ticket/10899 and
http://blog.joshcrompton.com/2012/09/how-to-use-sessions-in-django-unit-tests.html
FIXME this needs its own tests
'''
def new_function(self, *args, **kwargs):
from importlib import import_module
from django.conf import settings
engine = import_module(settings.SESSION_ENGINE)
store = engine.SessionStore()
store.save() # we need to make load() work, or the cookie is worthless
self.client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key
self.session_key = store.session_key
original_function(self, *args, **kwargs)
return new_function
示例5: test_post_logout_cycle_session
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def test_post_logout_cycle_session(self):
user = create_user()
data = {"new_password": "new password", "current_password": "secret"}
login_user(self.client, user)
self.client.force_login(user)
response = self.client.post(self.base_url, data)
self.assert_status_equal(response, status.HTTP_204_NO_CONTENT)
user.refresh_from_db()
session_id = self.client.cookies['sessionid'].coded_value
engine = importlib.import_module(settings.SESSION_ENGINE)
session = engine.SessionStore(session_id)
session_key = session[HASH_SESSION_KEY]
self.assertEqual(session_key, user.get_session_auth_hash())
示例6: delete_expired_sessions_and_workflows_forever
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def delete_expired_sessions_and_workflows_forever():
if settings.SESSION_ENGINE != "django.contrib.sessions.backends.db":
warnings.warn(
"WARNING: not deleting anonymous workflows because we do not know "
"which sessions are expired. Rewrite "
"delete_expired_sessions_and_workflows() to fix this problem."
)
# Run forever
while True:
await asyncio.sleep(999999)
while True:
try:
await benchmark(
logger,
delete_expired_sessions_and_workflows(),
"delete_expired_sessions_and_workflows()",
)
except:
logger.exception("Error deleting expired sessions and workflows")
await asyncio.sleep(ExpiryInterval)
示例7: login_user
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def login_user(self, userid):
"""
Login as specified user, does not depend on auth backend (hopefully)
This is based on Client.login() with a small hack that does not
require the call to authenticate()
"""
if not 'django.contrib.sessions' in settings.INSTALLED_APPS:
raise AssertionError("Unable to login without django.contrib.sessions in INSTALLED_APPS")
try:
user = User.objects.get(username=userid)
except User.DoesNotExist:
user = User(username=userid, password='')
user.save()
user.backend = "%s.%s" % ("django.contrib.auth.backends",
"ModelBackend")
engine = import_module(settings.SESSION_ENGINE)
# Create a fake request to store login details.
request = HttpRequest()
#if self.session:
# request.session = self.session
#else:
request.session = engine.SessionStore()
login(request, user)
# Set the cookie to represent the session.
session_cookie = settings.SESSION_COOKIE_NAME
self.cookies[session_cookie] = request.session.session_key
cookie_data = {
'max-age': None,
'path': '/',
'domain': settings.SESSION_COOKIE_DOMAIN,
'secure': settings.SESSION_COOKIE_SECURE or None,
'expires': None,
}
self.cookies[session_cookie].update(cookie_data)
# Save the session values.
request.session.save()
示例8: setUp
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def setUp(self):
classify = Classification.objects.create(c_name='test')
self.art = Article.objects.create(caption='article',
sub_caption='sub_article',
classification=classify,
content='article test',
publish=True)
settings.SESSION_ENGINE = 'django.contrib.sessions.backends.file'
engine = import_module(settings.SESSION_ENGINE)
store = engine.SessionStore()
store.save()
self.session = store
self.client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key
示例9: _session
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def _session(self):
"""
Obtains the current session variables.
"""
if apps.is_installed('django.contrib.sessions'):
engine = import_module(settings.SESSION_ENGINE)
cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None)
if cookie:
return engine.SessionStore(cookie.value)
else:
s = engine.SessionStore()
s.save()
self.cookies[settings.SESSION_COOKIE_NAME] = s.session_key
return s
return {}
示例10: login
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def login(self, **credentials):
"""
Sets the Factory to appear as if it has successfully logged into a site.
Returns True if login is possible; False if the provided credentials
are incorrect, or the user is inactive, or if the sessions framework is
not available.
"""
from django.contrib.auth import authenticate, login
user = authenticate(**credentials)
if (user and user.is_active and
apps.is_installed('django.contrib.sessions')):
engine = import_module(settings.SESSION_ENGINE)
# Create a fake request to store login details.
request = HttpRequest()
if self.session:
request.session = self.session
else:
request.session = engine.SessionStore()
login(request, user)
# Save the session values.
request.session.save()
# Set the cookie to represent the session.
session_cookie = settings.SESSION_COOKIE_NAME
self.cookies[session_cookie] = request.session.session_key
cookie_data = {
'max-age': None,
'path': '/',
'domain': settings.SESSION_COOKIE_DOMAIN,
'secure': settings.SESSION_COOKIE_SECURE or None,
'expires': None,
}
self.cookies[session_cookie].update(cookie_data)
return True
else:
return False
示例11: __init__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def __init__(self):
engine = import_module(settings.SESSION_ENGINE)
self.SessionStore = engine.SessionStore
示例12: handle
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def handle(self, **options):
engine = import_module(settings.SESSION_ENGINE)
try:
engine.SessionStore.clear_expired()
except NotImplementedError:
self.stderr.write("Session engine '%s' doesn't support clearing "
"expired sessions.\n" % settings.SESSION_ENGINE)
示例13: get_session_store_class
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def get_session_store_class(cls):
return import_module(settings.SESSION_ENGINE).SessionStore
示例14: __init__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def __init__(self, method = 'GET'):
super(EnhancedHttpRequest, self).__init__()
self.method = method
session_engine = import_module(settings.SESSION_ENGINE)
self.session = session_engine.SessionStore(session_key = None)
示例15: create_session
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def create_session(self):
session_engine = import_module(settings.SESSION_ENGINE)
store = session_engine.SessionStore()
store.save()
self.client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key