settings:
"""
Django settings for about_exam project.
Generated by 'django-admin startproject' using Django 1.11.26.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""
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.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '07k_$&dsr2qjyw=*oz#bum20gtj^6k_c!#u2%7ixbad7q51zpr'
# 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',
'app01.apps.App01Config',
]
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 = 'about_exam.urls'
#定义中间件:
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 = 'about_exam.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/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.11/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.11/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.11/howto/static-files/ #
# define a static file:
STATIC_URL = '/ static /'
ORM table data:
models:
Models django.db Import from
# the Create your Models here Wallpaper.
# Class Table is defined:
class the Classes (models.Model):
c_name = models.CharField (MAX_LENGTH = 32)
# define classes and teacher are many-ManyToManyField:
Teachers = Models .ManyToManyField ( "teacher")
# define teacher table:
class teacher (models.Model):
t_name = models.CharField (MAX_LENGTH = 32)
# sex defined length field is a default, selectively and M represents M represents:
sex = models.CharField (max_length = 1, choices = (( "1", " male"), ( "2", "F")))
#define integer IntegerField Age:
Age = models.IntegerField ()
#define students table:
class Student (models.Model):
S_NAME = models.CharField (MAX_LENGTH = 32)
Score = Models.IntegerField ()
# define many-class student table table, on_delete = models.CASCADE cascading deletes:
my_class = models.ForeignKey("Classes",on_delete=models.CASCADE)