• 【Django总结】Django setting.py学习


      1 """
      2 Django settings for my_site project.
      3 
      4 Generated by 'django-admin startproject' using Django 2.2.5.
      5 
      6 For more information on this file, see
      7 https://docs.djangoproject.com/en/2.2/topics/settings/
      8 
      9 For the full list of settings and their values, see
     10 https://docs.djangoproject.com/en/2.2/ref/settings/
     11 """
     12 
     13 import os
     14 
     15 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
     16 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     17 
     18 
     19 # Quick-start development settings - unsuitable for production
     20 # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
     21 
     22 # SECURITY WARNING: keep the secret key used in production secret!
     23 SECRET_KEY = 'q4vttubu2%s_x!fvq!f=b#_q@d$vp+4i@lab%24h0s*6^-500h'
     24 
     25 # SECURITY WARNING: don't run with debug turned on in production!
     26 DEBUG = True
     27 
     28 ALLOWED_HOSTS = ['*']
     29 
     30 
     31 # Application definition
     32 
     33 INSTALLED_APPS = [
     34     'django.contrib.admin',
     35     'django.contrib.auth',
     36     'django.contrib.contenttypes',
     37     'django.contrib.sessions',
     38     'django.contrib.messages',
     39     'django.contrib.staticfiles',
     40     'blog.apps.BlogConfig',
     41     'testblog.apps.TestblogConfig'
     42 ]
     43 
     44 MIDDLEWARE = [
     45     'django.middleware.security.SecurityMiddleware',
     46     'django.contrib.sessions.middleware.SessionMiddleware',
     47     'django.middleware.common.CommonMiddleware',
     48     'django.middleware.csrf.CsrfViewMiddleware',
     49     'django.contrib.auth.middleware.AuthenticationMiddleware',
     50     'django.contrib.messages.middleware.MessageMiddleware',
     51     'django.middleware.clickjacking.XFrameOptionsMiddleware',
     52 ]
     53 
     54 ROOT_URLCONF = 'my_site.urls'
     55 
     56 TEMPLATES = [
     57     {
     58         'BACKEND': 'django.template.backends.django.DjangoTemplates',
     59         'DIRS': [os.path.join(BASE_DIR, 'templates')],
     60         'APP_DIRS': True,
     61         'OPTIONS': {
     62             'context_processors': [
     63                 'django.template.context_processors.debug',
     64                 'django.template.context_processors.request',
     65                 'django.contrib.auth.context_processors.auth',
     66                 'django.contrib.messages.context_processors.messages',
     67             ],
     68         },
     69     },
     70 ]
     71 
     72 WSGI_APPLICATION = 'my_site.wsgi.application'
     73 
     74 
     75 # Database
     76 # https://docs.djangoproject.com/en/2.2/ref/settings/#databases
     77 
     78 # DATABASES = {
     79 #     'default': {
     80 #         'ENGINE': 'django.db.backends.sqlite3',
     81 #         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
     82 #     }
     83 # }
     84 import pymysql# 配置MySQL
     85 pymysql.install_as_MySQLdb()
     86 DATABASES = {
     87     'default': {
     88         'ENGINE': 'django.db.backends.mysql',   # 数据库引擎
     89         'NAME': 'django',         # 你要存储数据的库名,事先要创建之
     90         'USER': 'root',         # 数据库用户名
     91         'PASSWORD': '123456',     # 密码
     92         'HOST': 'localhost',    # 主机
     93         'PORT': '3306',         # 数据库使用的端口
     94     }
     95 }
     96 
     97 
     98 # Password validation
     99 # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
    100 
    101 AUTH_PASSWORD_VALIDATORS = [
    102     {
    103         'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    104     },
    105     {
    106         'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    107     },
    108     {
    109         'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    110     },
    111     {
    112         'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    113     },
    114 ]
    115 
    116 
    117 # Internationalization
    118 # https://docs.djangoproject.com/en/2.2/topics/i18n/
    119 
    120 LANGUAGE_CODE = 'zh-hans'
    121 
    122 TIME_ZONE = 'Asia/Shanghai'
    123 
    124 USE_I18N = True
    125 
    126 USE_L10N = True
    127 
    128 USE_TZ = True
    129 
    130 
    131 # Static files (CSS, JavaScript, Images)
    132 # https://docs.djangoproject.com/en/2.2/howto/static-files/
    133 
    134 STATIC_URL = '/static/'

    # 打印SQL语句
    LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
    'console': {
    'level': 'DEBUG',
    'class': 'logging.StreamHandler',
    },
    },
    'loggers': {
    'django.db.backends': {
    'handlers': ['console'],
    'propagate': True,
    'level': 'DEBUG',
    },
    }
    }
     
    作者:gtea 博客地址:https://www.cnblogs.com/gtea
  • 相关阅读:
    五种方式获取文件扩展名-转载未验证
    http状态代码-转载
    求两个时间的日期差-部分
    jsp相对路径解决方案
    OAUI前台设计(二)
    jsp生命周期
    OA办公页面设计
    Redis全局命令及数据结构
    Redis集群简介及部署
    sql中 in到底走不走索引
  • 原文地址:https://www.cnblogs.com/gtea/p/12900079.html
Copyright © 2020-2023  润新知