zoukankan      html  css  js  c++  java
  • Django框架文件解析--setting.py

    """
    Django settings for test01 project.
    
    Generated by 'django-admin startproject' using Django 1.8.2.
    
    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
    
    # django的Setting中只导入了os模块.
    
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    # '''
    # BASE_DIR 是通过os模块调用的当前项目文件夹,所在的绝对路径.
    #
    #     __file__ 是系统定义的,当前所执行文件的文件名. python中可以直接调用, 无需调用os模块.
    #     os.path.abspath() absolute_path:能够返回指定文件的绝对路径
    #     os.path.dirname() directory_name: 能够返回指定文件的父集目录.
    #
    #     此处调用了两次的dirname, 是从setting文件的路径向上两级,找django项目文件的文件夹.
    #     当django的setting.py文件发生改变的时候, 就需要改变此 BASE_DIR的写法.
    # '''
    
    # 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 = '!0vzeyf6nezt9jm4_wt1**lu687lp(mhqgbia#z2j(g32)*yp)'
    
    # 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',
        'booktest',  # 在这里关联新添加的应用.建立联系
    )
    
    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 = 'test01.urls'
    
    # 模板属性设置.
    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [os.path.join(BASE_DIR, 'template')],
    
    
            # !!!
            # 此处使用三引号注释, 会报错.
            # 字典内无法放入三引号注释
            # [#注释真正意义上的注释, 不会被解释器执行. 三引号注释需要解释器识别.]
            # 则: 项目中不该使用引号注释, 避免对效率产生影响.
    
            # 设置模板文件夹位置.
            # 为使项目文件转移之后依旧正常运行, 所以使用上方BASE_DIR做出的绝对路径,再后缀对标项目文件夹的相对路径.
            # 因绝对路径通过os模块得出, 不能直接通过字符串粘结方式增加相对路径.
            # 应使用os.path.join()方法, 先后传入绝对路径和相对路径
            #
            # 通常template模板文件夹直接定义在项目文件夹下.
    
            "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 = 'test01.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'),
    
            # qilite3,数据库引擎. 轻量级数据库, 之前适用于移动端. 更改为mysql,只需要修改django.db.backend后台数据.mysql
            # 需要安装pymysql, 并在__init__中导入,并使用install方法配置
            # pymysql.install_as_MySQLdb()
            'ENGINE': 'django.db.backends.mysql',
    
            # NAME写已经手动创建好的数据库名称.
            'NAME': "test01",
    
            # USER, PASSWORD 填入django框架链接mysql时候用的账号密码, 形成管道
            'USER':'mysql',
            'PASSWORD':'mysql',
    
            # 制定数据库所在的IP地址, 为本地时候, localhost或127.0.0.1
            'HOST':'localhost',
    
            # 填入数据库服务使用的端口号, 默认为3306, 参数为整数类型.
            'PORT':3306,
    
    
            
            # 在使用object类操作或者使用manage.py操作mysql或者其他数据库的时候,
            # 实质上也是通过django框架把指令转化成,相应数据库的操作语句
            #
            # 在操作mysql, 想要同步看到mysql的操作记录, 需要配置相关文件.
            # 1. 使用root权限, 在/etc/mysql/mysql.conf.d/mysql.cnf文件的第68,69取消注释
            # 2. 使用sudo权限, 重启mysql服务, $sudo service mysql restart
            # 3. 重启之后的mysql就会产生log日志, log日志地址在/var/log/mysql/mysql.log中.(在/var[various不同的]中放置的就是在linux系统运行过程中,经常变化的文件,log日志就是其中重要的组成部分)
            # 4. 使用tail命令查看log日志的变化 $sudo tail -f /var/log/mysql/mysql.log命令, tail尾巴,查看文件最后, -f用于监视文件增长.
    
    
        }
    }
    
    # Internationalization
    # https://docs.djangoproject.com/en/1.8/topics/i18n/
    
    LANGUAGE_CODE = 'zh-hans'
    
    # '''
    # 在此处进行后台管理界面的语言本地化
    #
    # 语言代码缩写普遍采用的方式是 26字母本地表达+英语
    #
    # zh-CN表示中文(包含中文简体和繁体,以及各地大小方言)(zhiguo-CHINA)
    # zh-hans表简体中文(zhiguo-hanzi-simplified)
    # zh-hant表繁体,(zhiguo-hanzi-traditional)
    # '''
    
    TIME_ZONE = 'Asia/Shanghai'
    
    # '''
    # UTC Coordinated Universal Time 世界协调时, 1884年美国华盛顿确立UTC时间以英国为中时区"UTC"
    # 国内时区为 UTC+8 东八区时间, 此处可以直接填写大洲+城市
    # 一般填写上海.中间斜线隔开.
    # '''
    
    USE_I18N = True
    
    USE_L10N = True
    
    USE_TZ = True
    
    # Static files (CSS, JavaScript, Images)
    # https://docs.djangoproject.com/en/1.8/howto/static-files/
    
    STATIC_URL = '/static/'
    
    # 设置redis存储session信息
    SESSION_ENGINE = 'redis_sessions.session'
    # redis服务器的ip地址
    SESSION_REDIS_HOST = 'localhost'
    # redis服务器的端口号,直接填写数字
    SESSION_REDIS_PORT = 6379
    # 选择redis数据库的序号
    SESSION_REDIS_DB = 2
    # redis数据库的密码
    SESSION_REDIS_PASSWORD = ''
    # redis数据库中存储session标识码的前缀
    SESSION_REDIS_PREFIX = 'session'  # session会生成唯一标识码,存储在redis中属于value.此项设置就是设置标识码在redis中存储的key的前缀.
    
    # 设置redis存放session信息配置的时候, 除了engine之外, 所有的选项都需要添加REDIS字段
  • 相关阅读:
    [leetcode]Copy List with Random Pointer @ Python
    [leetcode]Convert Sorted List to Binary Search Tree @ Python
    [leetcode]Convert Sorted Array to Binary Search Tree @ Python
    [leetcode]Binary Tree Level Order Traversal II @ Python
    [leetcode]Minimum Depth of Binary Tree @ Python
    [leetcode]Binary Tree Zigzag Level Order Traversal @ Python
    [leetcode]Binary Tree Level Order Traversal @ Python
    [leetcode]Sum Root to Leaf Numbers @ Python
    [leetcode]Flatten Binary Tree to Linked List @ Python
    [leetcode]Binary Tree Postorder Traversal @ Python
  • 原文地址:https://www.cnblogs.com/jrri/p/11492011.html
Copyright © 2011-2022 走看看