Django 开发服务器不断注销

2023-12-12

我在 settings.py 中将 SESSION_COOKIE_AGE 设置为 360,但是在我开发服务器时它总是将我注销:((

为什么会发生这种情况以及如何防止这种情况......?

Thanks!

这是我的设置.py:

设置.py

# Django settings for quora project.
import os.path

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    ('myname', 'myemail'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'mydb',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': '',
        'PASSWORD': '',
        'HOST': 'localhost',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}

# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True

PROJECT_ROOT = os.path.dirname(__file__)

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = '/media/'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = ''

# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, 'static'),
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = '..........'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'blog.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'blog.wsgi.application'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.humanize',

    # Additional
    'django.contrib.admin',
    'rest_framework',

    # Applications
    'core',
    'app_blog',
    'app_registration',
)

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}

LOGIN_URL = '/accounts/login/'
LOGIN_REDIRECT_URL = '/'

#Cookie
SESSION_COOKIE_AGE = 360

#Custom user model
AUTH_USER_MODEL = "app_registration.MyUser"
AUTH_PROFILE_MODULE = 'app_registration.MyUserProfile'


# Registration
REGISTRATION_OPEN = True
ACCOUNT_ACTIVATION_DAYS = 7

我相信只有cookies的年龄是不够的,360仅意味着可用360秒:

#Cookie name. this can be whatever you want
SESSION_COOKIE_NAME='sessionid'  # use the sessionid in your views code
#the module to store sessions data
SESSION_ENGINE='django.contrib.sessions.backends.db'    
#age of cookie in seconds (default: 2 weeks)
SESSION_COOKIE_AGE= 24*60*60*7 # the number of seconds for only 7 for example
#whether a user's session cookie expires when the web browser is closed
SESSION_EXPIRE_AT_BROWSER_CLOSE=False
#whether the session cookie should be secure (https:// only)
SESSION_COOKIE_SECURE=False
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Django 开发服务器不断注销 的相关文章

随机推荐

  • 数据框为一列选择最大值,但输出另一列的值

    我有一个数据框 其值类似于下面 A10d B10d C10d A B C Strategy 20 10 5 3 5 1 3 该策略选择 A10d B10d C10d 中的最大值并返回 A B C 的值 在这种情况下 A10d 是最大的 策略
  • Susy grid - 有什么(简单?)方法可以使“列”具有相同的高度?

    让我的脚接触 Susy sass haml 等 使用调整后的中间人 来自主分支的最新 susy 在 grid css scss 中有这个 import susy total columns 8 column width 4em gutter
  • Perl 主机到 IP 解析

    我想将主机名解析为 IP 地址 使用以下 Socket 就可以了 ip gethostbyname host or die Can t resolve ip for host n ip inet ntoa inet aton host 这工
  • Gradle 相关任务不会将命令行选项传递给父任务

    我正在编写一个自定义 Gradle 任务 它接受来自命令行的选项 该部分按预期工作 导致我出现问题的是 调用依赖任务时 命令行选项被拒绝 因为它与依赖任务无关 这是演示该问题的示例 class CustomTask extends Defa
  • 将图标添加到自定义 WooCommerce 支付网关

    我想向我的支付网关添加自定义图标 我已阅读 WOO 网关 API 但获得的帮助为零 这是我下面的代码 请帮助我找到一种包含该图标的实用方法 以便我的前端有一个图标 谢谢
  • 在 Struts 2 中动态生成电子邮件模板

    场景是用户请假 当他请求休假时 系统会向审批者和用户发送一封电子邮件 其中包含有关休假的详细信息 我被困在这一点上 如何创建一个模板 该模板将根据请求休假的用户的名称自动更新 我看到了 asp net 应用程序 它是通过使用类似的东西在模板
  • 为什么Java中没有SortedList?

    在Java中有SortedSet and SortedMap接口 两者都属于Java集合框架并提供访问元素的排序方式 然而 据我了解 没有SortedList在爪哇 您可以使用java util Collections sort 对列表进行
  • 静态解析符号值时遇到错误。不支持函数调用。考虑替换函数或 lambda?

    尝试启动 npm 时出现错误 Error encountered resolving symbol values statically Function calls are not supported Consider replacing
  • 从进程获取实时输出

    我的项目有问题 我想启动一个进程 7z exe 控制台版本 我尝试了三种不同的方法 Process StandardOutput ReadToEnd 已接收输出数据 开始输出读取行 流写入器 什么都不起作用 它总是 等待 过程结束以显示我想
  • Ruby:无法在 Windows 上安装 Watir Gem

    瓦提尔的网站说我需要 Ruby 1 8 6 我正在运行它 Windows 安装应该像这样简单gem install watir 但是当我运行它时 我得到了这个 C Users Ryguy Code gt gem install watir
  • 在循环 R 中迭代时从函数返回值

    我已经远离了 R 中的函数 但认为这是更好的做法 现在我有这个问题 我写我的函数 myFunction lt function tab takes tabular input inP lt c for x in 1 dim tab 1 it
  • 增强 PowerShell 脚本以查询 AsBuiltReport 框架内 GPO 上的端口

    我得到了当前的脚本 来自这个答案 我想改进 如果在入站方向内启用并允许这些端口 则脚本应检索所需的端口 操作 启用 方向的过滤器工作完美 但我仍然需要本地端口的过滤器仅检索定义端口内的唯一结果 但仍显示其他端口 附加问题 如何将机器的 IP
  • 长按监听器 ListActivity 类

    我有一个使用 ListView 的应用程序 我设置了 onListItemClick 事件来查看有关联系人的详细信息 我想实现 onLongListItemClick 来显示一个对话框 但我不知道为什么它不起作用 我的意思是什么也没有发生
  • Visual Studio Code c++11 扩展警告

    我正在学习 C 并且正在使用 Mac 版 Visual Studio Code 我使用 Code Runner 来运行我的程序 我的问题是 当我使用 c 11 中的某些内容 如 auto 进行变量声明时 Visual Studio Code
  • 如何自定义UITabBarController的“更多”按钮?

    我将 UITabBarController 添加为 RootView 并且我还知道当您有超过 5 个 tabBarItem 时 会自动添加 更多 按钮 所以一切都很完美 但我有两个问题 1 如何在 更多 TabBarItem上设置图像 2
  • Mapbox GL JS 在图层中的特定功能上设置 Paint 属性

    我使用 Mapbox Studio 作为地图和样式的基础 然后使用 HTML 来实现其他地图功能 其中一项功能是在悬停或鼠标输入时更改图标不透明度 当您直接在 HTML 中创建它时 我检查了其他示例和所有其他参考功能 我设法改变不透明度 但
  • 队列不自然排序[重复]

    这个问题在这里已经有答案了 可能的重复 为什么java中的PriorityQueue会出现这种奇怪的顺序 请参阅下面的代码 public static void main String args Queue
  • 使用 MIPS 汇编中的逻辑移位乘以 2 的幂

    有人可以指导我如何在 MIPS 汇编中使用移位来制作乘法代码吗 我不明白数字 2 n 如何帮助我使用奇数被乘数进行乘法 我目前有这段代码 我正在尝试制作一个计算器 text li v0 4 la a0 ask 1 syscall li v0
  • 使用 PHP 抓取完整图像 src

    我正在尝试用 php 抓取 img src 我可以很好地获取 src 但是如果 src 不包含完整路径 那么我无法真正重用它 有没有办法使用php获取图像的完整路径 如果使用右键菜单 浏览器可以获取它 IE 如何获取包含以下两个示例之一中的
  • Django 开发服务器不断注销

    我在 settings py 中将 SESSION COOKIE AGE 设置为 360 但是在我开发服务器时它总是将我注销 为什么会发生这种情况以及如何防止这种情况 Thanks 这是我的设置 py 设置 py Django settin