0x01 环境搭建

1、准备sudo pip3 install -U pip

pip install django

pip install ipython mysqlclient

2、创建项目django-admin startproject myProject //创建项目

cd myProject

python3 manage.py startapp myApp //创建应用

3、启动python3 manage.py runserver 0:8080

4、基本目录结构myProject

├── db.sqlite3

├── manage.py

├── myApp

│ ├── admin.py

│ ├── apps.py

│ ├── __init__.py

│ ├── migrations

│ │ ├── 0001_initial.py

│ │ ├── __init__.py

│ │ └── __pycache__

│ │ ├── 0001_initial.cpython-35.pyc

│ │ └── __init__.cpython-35.pyc

│ ├── models.py

│ ├── __pycache__

│ │ ├── admin.cpython-35.pyc

│ │ ├── apps.cpython-35.pyc

│ │ ├── __init__.cpython-35.pyc

│ │ ├── models.cpython-35.pyc

│ │ └── views.cpython-35.pyc

│ ├── templates

│ │ └── myApp

│ │ └── detail.html

│ ├── tests.py

│ └── views.py

└── myProject

├── __init__.py

├── __pycache__

│ ├── __init__.cpython-35.pyc

│ ├── settings.cpython-35.pyc

│ ├── urls.cpython-35.pyc

│ └── wsgi.cpython-35.pyc

├── settings.py

├── urls.py

└── wsgi.py

5、其他使用ipython接口

python3 manage.py shell在models里进行了数据库的修改以后python3 manage.py makemigrations myApp

python3 manage.py sqlmigrate myApp 0001

python3 manage.py migrate检查项目是否可以正常启动

python3 manage.py check

0x02 实战项目

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐