Django

概览

Django 是一个由 Python 编写的一个开放源代码的 Web 应用框架
Django 本身基于 MVC 模型,即 Model(模型)+ View(视图)+ Controller(控制器)设计模式
Django采用了MTV的框架模式,即模型(Model)、模板(Template)和视图(Views),三者之间各自负责不同的职责
Python 加 Django 是快速开发、设计、部署网站的常用组合

What Python version can I use with Django?
Django version	         Python versions
1.11	                 2.7, 3.4, 3.5, 3.6, 3.7 (added in 1.11.17)
2.0	                     3.4, 3.5, 3.6, 3.7
2.1	                     3.5, 3.6, 3.7
2.2	                     3.5, 3.6, 3.7, 3.8 (added in 2.2.8)
3.0	                     3.6, 3.7, 3.8

MVC 模式(Model–view–controller)是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model)、视图(View)和控制器(Controller)。

安装

as4k@bogon ~ % python3 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/  Django
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting Django
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ca/ab/5e004afa025a6fb640c6e983d4983e6507421ff01be224da79ab7de7a21f/Django-3.0.8-py3-none-any.whl (7.5 MB)
     |████████████████████████████████| 7.5 MB 3.0 MB/s 
Collecting sqlparse>=0.2.2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/85/ee/6e821932f413a5c4b76be9c5936e313e4fc626b33f16e027866e1d60f588/sqlparse-0.3.1-py2.py3-none-any.whl (40 kB)
     |████████████████████████████████| 40 kB 7.0 MB/s 
Collecting pytz
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4f/a4/879454d49688e2fad93e59d7d4efda580b783c745fd2ec2a3adf87b0808d/pytz-2020.1-py2.py3-none-any.whl (510 kB)
     |████████████████████████████████| 510 kB 5.3 MB/s 
Collecting asgiref~=3.2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d5/eb/64725b25f991010307fd18a9e0c1f0e6dff2f03622fc4bcbcdb2244f60d6/asgiref-3.2.10-py3-none-any.whl (19 kB)
Installing collected packages: sqlparse, pytz, asgiref, Django
  WARNING: The script sqlformat is installed in '/Users/as4k/Library/Python/3.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The script django-admin is installed in '/Users/as4k/Library/Python/3.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed Django-3.0.8 asgiref-3.2.10 pytz-2020.1 sqlparse-0.3.1

as4k@bogon ~ % python3 -m pip list
Package    Version
---------- -------
asgiref    3.2.10
Django     3.0.8
pip        20.1.1
pytz       2020.1
setuptools 40.8.0
six        1.12.0
sqlparse   0.3.1
wheel      0.33.1


默认依赖的sqlite数据库版本要求
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17)

快速上手

/Users/as4k/Library/Python/3.7/bin

as4k@bogon xtestcode % pwd
/Users/as4k/As4k/xtestcode
as4k@bogon xtestcode % /Users/as4k/Library/Python/3.7/bin/django-admin  startproject mysite

python3 manage.py runserver
OR   python3 manage.py runserver 8080
OR   python3 manage.py runserver 0.0.0.0:8000


/Users/as4k/Library/Python/3.7/bin/django-admin  startproject HelloWorld

https://www.runoob.com/django/django-first-app.html

cd /Users/as4k/As4k/xtestcode
python3 manage.py startapp polls

开源CMDB

安装 https://github.com/open-cmdb/cmdb   OR  https://zhuanlan.zhihu.com/p/34191320
默认账号密码  admin / cmdbcmdb
访问 http://localhost:80

[root@node6 ~]# docker ps -a
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                NAMES
4ef28d885895        mingmingtang/cmdb     "start"                  4 minutes ago       Up 4 minutes        0.0.0.0:80->80/tcp   cmdb
99856915dcdb        elasticsearch:5.6.8   "/docker-entrypoint.…"   6 minutes ago       Up 6 minutes        9200/tcp, 9300/tcp   cmdb-es
dc2cd944e927        mysql:5.7.21          "docker-entrypoint.s…"   6 minutes ago       Up 6 minutes        3306/tcp             cmdb-db

参考资料

https://docs.djangoproject.com/en/3.0/intro/install/
https://docs.djangoproject.com/en/3.0/topics/install/#installing-official-release
https://www.runoob.com/django/django-install.html
https://docs.djangoproject.com/zh-hans/3.0/intro/tutorial07/

https://www.django.cn/