首页 > 其他 > 详细

django

时间:2019-02-20 00:20:01      阅读:196      评论:0      收藏:0      [点我收藏+]

 web框架的功能:

  1.socket收发消息    (wsgi)

  2.根据不同的地址返回不同的内容

  3.返回动态页面(字符串的替换)

web框架的分类: 

 1. gjango + wsgiref

  2. flask     janja2

  3. tornado .

Django

Django官网下载页面:https://www.djangoproject.com/download/

安装最新LTS版:

pip3 install django==1.11.15

创建django项目:

django-admin startproject  mysite   #创建一个名为mysite 的项目 或用pycharm创建 (命令创建的没有页面的路径)

目录介绍

mysite/
├── manage.py  # 管理文件
└── mysite  # 项目目录
    ├── __init__.py
    ├── settings.py  # 配置
    ├── urls.py  # 路由 --> URL和函数的对应关系
    └── wsgi.py  # runserver命令就使用wsgiref模块做简单的web server

启动项目

python manage.py runserver 127.0.0.1:8000
python manage.py runserver 80  #指定80端口启动 

setting.py 配置文件

"""
Django settings for qqq project.

Generated by ‘django-admin startproject‘ using Django 1.11.15.

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 = t8$e3*a^7@)zgh@1et(om%b3xtmj8!9$+^tma=m_(zy#qb7w0%

# SECURITY WARNING: don‘t run with debug turned on in production!
DEBUG = True        #调试功能 开发时为True  上线时改为False

ALLOWED_HOSTS = [*]         #允许访问的主机 ‘*‘ 表示所有


# Application definition

INSTALLED_APPS = [            #配置app
    django.contrib.admin,
    django.contrib.auth,
    django.contrib.contenttypes,
    django.contrib.sessions,
    django.contrib.messages,
    django.contrib.staticfiles,
   ‘app1.apps.App01config‘   #将创建的app加入进来 ] 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 = qqq.urls #url路由的位置 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 = qqq.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/ STATIC_URL = /static/ #静态文件的别名,找静态文件会在这个目录下的各个子目录中找
 STATICFILES_DIRS = [ #静态文件的位置 
os.path.join(BASE_DIR,static) ]

创建app

python3 manage.py startapp app1  #创建名为app1的app

 

 

 

 

 

 

     

django

原文:https://www.cnblogs.com/ywrj/p/10404067.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!