当前位置: 首页>>代码示例>>Python>>正文


Python settings.SESSION_COOKIE_NAME属性代码示例

本文整理汇总了Python中django.conf.settings.SESSION_COOKIE_NAME属性的典型用法代码示例。如果您正苦于以下问题:Python settings.SESSION_COOKIE_NAME属性的具体用法?Python settings.SESSION_COOKIE_NAME怎么用?Python settings.SESSION_COOKIE_NAME使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在django.conf.settings的用法示例。


在下文中一共展示了settings.SESSION_COOKIE_NAME属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_modify_session

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SESSION_COOKIE_NAME [as 别名]
def test_modify_session(client, logged_in):
    if logged_in:
        user = User.objects.create_superuser("user", "", "secret")
        client.force_login(user)
    else:
        user = None

    client.get("/read_session/", HTTP_USER_AGENT="TestUA/1.1")
    client.get("/modify_session/", HTTP_USER_AGENT="TestUA/1.1")
    data = json.loads(client.get("/read_session/", HTTP_USER_AGENT="TestUA/1.1").content.decode("UTF-8"))
    assert data["FOO"] == "BAR"
    assert data[USER_AGENT_SESSION_KEY] == "TestUA/1.1"
    if user:
        assert str(data[SESSION_KEY]) == str(user.id)

    assert settings.SESSION_COOKIE_NAME in client.cookies
    session = Session.objects.get(pk=client.cookies[settings.SESSION_COOKIE_NAME].value)
    assert session.user_agent == "TestUA/1.1"
    assert session.ip == "127.0.0.1"
    assert session.user == user 
开发者ID:QueraTeam,项目名称:django-qsessions,代码行数:22,代码来源:test_middleware.py

示例2: __init__

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SESSION_COOKIE_NAME [as 别名]
def __init__(self, *args, **kwargs):
        self.protected_cookies = get_config_setting(
            "SESSION_COOKIE_SAMESITE_KEYS", set()
        )

        if not isinstance(self.protected_cookies, (list, set, tuple)):
            raise ValueError(
                "SESSION_COOKIE_SAMESITE_KEYS should be a list, set or tuple."
            )

        self.protected_cookies = set(self.protected_cookies)
        self.protected_cookies |= {
            settings.SESSION_COOKIE_NAME,
            settings.CSRF_COOKIE_NAME,
        }

        samesite_flag = get_config_setting("SESSION_COOKIE_SAMESITE", "")
        self.samesite_flag = (
            str(samesite_flag).capitalize() if samesite_flag is not None else ""
        )
        self.samesite_force_all = get_config_setting(
            "SESSION_COOKIE_SAMESITE_FORCE_ALL"
        )

        return super(CookiesSameSite, self).__init__(*args, **kwargs) 
开发者ID:jotes,项目名称:django-cookies-samesite,代码行数:27,代码来源:middleware.py

示例3: __call__

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SESSION_COOKIE_NAME [as 别名]
def __call__(self, request):
        # Code to be executed for each request before
        # the view (and later middleware) are called.

        response = self.get_response(request)

        # Code to be executed for each request/response after
        # the view is called.
        from django.conf import settings
        from polaris import settings as polaris_settings

        if (
            settings.SESSION_COOKIE_NAME in response.cookies
            and not polaris_settings.LOCAL_MODE
        ):
            response.cookies[settings.SESSION_COOKIE_NAME]["samesite"] = "None"
            response.cookies[settings.SESSION_COOKIE_NAME]["secure"] = True

        return response 
开发者ID:stellar,项目名称:django-polaris,代码行数:21,代码来源:middleware.py

示例4: login

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SESSION_COOKIE_NAME [as 别名]
def login(
        self, username=None, password=USER_PASSWORD, manually=False
    ):
        if username is None:
            username = self.get_my_username()

        if manually:
            self.get_element('id=id_username').clear()
            self.get_element('id=id_password').clear()
            self.get_element('id=id_username').send_keys(username)
            self.get_element('id=id_password').send_keys(password)
            self.click_link('id_login')
            return

        session_key = self.session_keys[username]
        ## to set a cookie we need to first visit the domain.
        ## 404 pages load the quickest!
        self.browser.get(urljoin(Url.ROOT, "/404_no_such_url/"))
        self.browser.add_cookie(dict(
            name=settings.SESSION_COOKIE_NAME,
            value=session_key,
            path='/',
        ))
        self.go_to_url(Url.ROOT) 
开发者ID:pythonanywhere,项目名称:dirigible-spreadsheet,代码行数:26,代码来源:functionaltest.py

示例5: establish_session

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SESSION_COOKIE_NAME [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 
开发者ID:metabolize,项目名称:drf-to-s3,代码行数:25,代码来源:util.py

示例6: dispatch

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SESSION_COOKIE_NAME [as 别名]
def dispatch(self, request, *args, **kwargs):
        response = super().dispatch(request, *args, **kwargs)

        messages.success(self.request, _('You have been successfully logged out.'))
        # By default, logging out will generate a fresh sessionid cookie. We want to use the
        # absence of sessionid as an indication that front-end pages are being viewed by a
        # non-logged-in user and are therefore cacheable, so we forcibly delete the cookie here.
        response.delete_cookie(
            settings.SESSION_COOKIE_NAME,
            domain=settings.SESSION_COOKIE_DOMAIN,
            path=settings.SESSION_COOKIE_PATH
        )

        # HACK: pretend that the session hasn't been modified, so that SessionMiddleware
        # won't override the above and write a new cookie.
        self.request.session.modified = False

        return response 
开发者ID:wagtail,项目名称:wagtail,代码行数:20,代码来源:account.py

示例7: login

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SESSION_COOKIE_NAME [as 别名]
def login(self, superuser=False):
        """ Craft cookie to fake a login. """
        assert auth, "auth.py could not be imported from acceptance_tests"

        # First visit a guaranteed 404, just to get selenium in the right domain (it doesn't like us setting cookies
        # for places we aren't in, even if we specify a domain).
        self.driver.get('http://localhost:19150/not-a-place')

        self.driver.add_cookie({
            'name': settings.SESSION_COOKIE_NAME,
            'value': auth.SESSION_SUPER_KEY if superuser else auth.SESSION_KEY,
            'secure': False,
            'path': '/',
        })

        self.driver.refresh() 
开发者ID:edx,项目名称:credentials,代码行数:18,代码来源:mixins.py

示例8: _get_session

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SESSION_COOKIE_NAME [as 别名]
def _get_session(self):
        session_cookie = self._driver.get_cookie(settings.SESSION_COOKIE_NAME)
        if session_cookie is None:
            # Create new
            session = get_session_store()
            cookie_data = {'name': settings.SESSION_COOKIE_NAME,
                           'value': session.session_key,
                           'path': '/',
                           'secure': False,
                           }
            if self._driver.name == 'phantomjs':
                # Not sure why this is needed, but it seems to do the trick
                cookie_data['domain'] = '.localhost'

            self._add_cookie(cookie_data)
        else:
            session = get_session_store(session_key=session_cookie['value'])
        return session 
开发者ID:django-functest,项目名称:django-functest,代码行数:20,代码来源:funcselenium.py

示例9: test_httponly_session_cookie

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SESSION_COOKIE_NAME [as 别名]
def test_httponly_session_cookie(self):
        request = RequestFactory().get('/')
        response = HttpResponse('Session test')
        middleware = SessionMiddleware()

        # Simulate a request the modifies the session
        middleware.process_request(request)
        request.session['hello'] = 'world'

        # Handle the response through the middleware
        response = middleware.process_response(request, response)
        self.assertIs(response.cookies[settings.SESSION_COOKIE_NAME]['httponly'], True)
        self.assertIn(
            cookies.Morsel._reserved['httponly'],
            str(response.cookies[settings.SESSION_COOKIE_NAME])
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:18,代码来源:tests.py

示例10: test_no_httponly_session_cookie

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SESSION_COOKIE_NAME [as 别名]
def test_no_httponly_session_cookie(self):
        request = RequestFactory().get('/')
        response = HttpResponse('Session test')
        middleware = SessionMiddleware()

        # Simulate a request the modifies the session
        middleware.process_request(request)
        request.session['hello'] = 'world'

        # Handle the response through the middleware
        response = middleware.process_response(request, response)
        self.assertEqual(response.cookies[settings.SESSION_COOKIE_NAME]['httponly'], '')
        self.assertNotIn(
            cookies.Morsel._reserved['httponly'],
            str(response.cookies[settings.SESSION_COOKIE_NAME])
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:18,代码来源:tests.py

示例11: test_session_delete_on_end

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SESSION_COOKIE_NAME [as 别名]
def test_session_delete_on_end(self):
        request = RequestFactory().get('/')
        response = HttpResponse('Session test')
        middleware = SessionMiddleware()

        # Before deleting, there has to be an existing cookie
        request.COOKIES[settings.SESSION_COOKIE_NAME] = 'abc'

        # Simulate a request that ends the session
        middleware.process_request(request)
        request.session.flush()

        # Handle the response through the middleware
        response = middleware.process_response(request, response)

        # The cookie was deleted, not recreated.
        # A deleted cookie header looks like:
        #  Set-Cookie: sessionid=; expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0; Path=/
        self.assertEqual(
            'Set-Cookie: {}=""; expires=Thu, 01 Jan 1970 00:00:00 GMT; '
            'Max-Age=0; Path=/'.format(
                settings.SESSION_COOKIE_NAME,
            ),
            str(response.cookies[settings.SESSION_COOKIE_NAME])
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:27,代码来源:tests.py

示例12: login_user

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SESSION_COOKIE_NAME [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() 
开发者ID:sfu-fas,项目名称:coursys,代码行数:42,代码来源:testing.py

示例13: setUp

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SESSION_COOKIE_NAME [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 
开发者ID:bluedazzle,项目名称:django-angularjs-blog,代码行数:15,代码来源:test_view_blog.py

示例14: _session

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SESSION_COOKIE_NAME [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 {} 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:17,代码来源:client.py

示例15: login

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SESSION_COOKIE_NAME [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 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:43,代码来源:client.py


注:本文中的django.conf.settings.SESSION_COOKIE_NAME属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。