1.配置静态文件
STATIC_URL = '/static/' #css,js等静态文件的存储目录
STATICFILES_DIRS=(
os.path.join(BASE_DIR,'static'), #文件路径
MEDIA_URL = '/media/' #静态文件长传目录,可以理解为用户上传
MEDIA_ROOT=os.path.join(BASE_DIR,'static') #文件路径
2.mysql数据库配置
DATABASES={ #设置mysql数据库
'default':{
'ENGINE': 'django.db.backends.mysql',
'NAME':'shopcity', #项目名
'HOST':'localhost', #数据库主机
'USER':'root', #用户
'PASSWORD':'', #密码(可设置)
'PORT':3306, #端口号
}
}
split3数据库配置
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), #设置sqlite3数据库
}
}
3.设置打印日志到屏幕
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console':{
'level':'DEBUG',
'class':'logging.StreamHandler',
},
},
'loggers': {
'django.db.backends': {
'handlers': ['console'],
'propagate': True,
'level':'DEBUG',
},
}
}
4.语言
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
5.配置模板
TEMPLATE_DIRS = (
os.path.join(BASE_DIR,'templates'),
)
6.setting文件默认代码注释
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
#向上找两级,获取基地址
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '@jm-+mpxpv-@3%=o^fij9w+dtsil=18&6bpt*akkv+=422-vsl'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
#APP信息,自己新建的项目如果没有自动加入,可以再次手动加进去
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
]
# 中间件配置
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
#'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'django_lesson.urls'
#模板(HTML页面)路径相关配置
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'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 = 'django_lesson.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
#数据库配置
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
#认证相关
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/
# 语言
LANGUAGE_CODE = 'en-us'
# 时间
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
# 静态文件
STATIC_URL = '/static/'
#单级目录静态文件
# STATICFILES_DIRS=(
# os.path.join(BASE_DIR,"statics"),
# )
#多级目录静态文件
STATICFILES_DIRS=(
os.path.join(BASE_DIR,"blog","statics"),
)