django 学习(一)
1.pip install django == x.x -i https://pypi.douban.com/simple
2.django-admin startproject DataFactory
3...\DataFactory> python .\manage.py startapp myapp
4.修改settings 配置文件。settings.py
1 """ 2 Django settings for DataFactory project. 3 4 Generated by 'django-admin startproject' using Django 2.2. 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 # Quick-start development settings - unsuitable for production 19 # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ 20 21 # SECURITY WARNING: keep the secret key used in production secret! 22 SECRET_KEY = 'cvs)6y07$yee8-op)meo=%#*9kedoh@tiuch8*=wm%fe0)pwl=' 23 24 # SECURITY WARNING: don't run with debug turned on in production! 25 DEBUG = True 26 27 ALLOWED_HOSTS = ['*', ] 28 29 # Application definition 30 31 INSTALLED_APPS = [ 32 'django.contrib.admin', 33 'django.contrib.auth', 34 'django.contrib.contenttypes', 35 'django.contrib.sessions', 36 'django.contrib.messages', 37 'django.contrib.staticfiles', 38 'myapp' 39 ] 40 41 MIDDLEWARE = [ 42 'django.middleware.security.SecurityMiddleware', 43 'django.contrib.sessions.middleware.SessionMiddleware', 44 'django.middleware.common.CommonMiddleware', 45 # 'django.middleware.csrf.CsrfViewMiddleware', # 身份认证,后期自己写 46 'django.contrib.auth.middleware.AuthenticationMiddleware', 47 'django.contrib.messages.middleware.MessageMiddleware', 48 'django.middleware.clickjacking.XFrameOptionsMiddleware', 49 ] 50 51 ROOT_URLCONF = 'DataFactory.urls' 52 53 TEMPLATES = [ 54 { 55 'BACKEND': 'django.template.backends.django.DjangoTemplates', 56 'DIRS': [], 57 'APP_DIRS': True, 58 'OPTIONS': { 59 'context_processors': [ 60 'django.template.context_processors.debug', 61 'django.template.context_processors.request', 62 'django.contrib.auth.context_processors.auth', 63 'django.contrib.messages.context_processors.messages', 64 ], 65 }, 66 }, 67 ] 68 69 WSGI_APPLICATION = 'DataFactory.wsgi.application' 70 71 # Database 72 # https://docs.djangoproject.com/en/2.2/ref/settings/#databases 73 74 DATABASES = { 75 'default': { 76 'ENGINE': 'django.db.backends.sqlite3', 77 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 78 } 79 } 80 81 # Password validation 82 # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators 83 84 AUTH_PASSWORD_VALIDATORS = [ 85 { 86 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 87 }, 88 { 89 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 90 }, 91 { 92 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 93 }, 94 { 95 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 96 }, 97 ] 98 99 # Internationalization 100 # https://docs.djangoproject.com/en/2.2/topics/i18n/ 101 102 LANGUAGE_CODE = 'zh-hans' 103 104 TIME_ZONE = 'Asia/Shanghai' 105 106 USE_I18N = True 107 108 USE_L10N = True 109 110 USE_TZ = True 111 112 # Static files (CSS, JavaScript, Images) 113 # https://docs.djangoproject.com/en/2.2/howto/static-files/ 114 115 STATIC_URL = '/static/' # 静态文件引入
5.运行 : python manage.py runserver 8000
6.同步表结构:python manage.py makemigrations /创建数据迁移的语句
python manage.py migrate /提交
7.创建管理员用户: python manage.py createsuperuser
本文来自博客园,作者:kaer_invoker,转载请注明原文链接:https://www.cnblogs.com/invoker2021/p/15835038.html