1. 安装Python
官网:https://www.python.org/downloads/windows/
Download Windows x86-64 executable installer
2. 安装pip和Django
自行安装,直接执行pip install django
PS D:\CODE\career> pip install django
Requirement already satisfied: django in c:\users\liguangliang\appdata\local\programs\python\python37\lib\site-packages\django-3.2-py3.7.egg (3.2)
Requirement already satisfied: asgiref>=3.2.10 in c:\users\liguangliang\appdata\local\programs\python\python37\lib\site-packages\asgiref-3.2.10-py3.7.egg (from django) (3.2.10)
Requirement already satisfied: pytz in c:\users\liguangliang\appdata\local\programs\python\python37\lib\site-packages\pytz-2020.1-py3.7.egg (from django) (2020.1)
Requirement already satisfied: sqlparse>=0.2.2 in c:\users\liguangliang\appdata\local\programs\python\python37\lib\site-packages\sqlparse-0.3.1-py3.7.egg (from django) (0.3.1)
3. 创建项目
在D:\CODE
路径下,
- 执行
django-admin startproject career
创建项目,
PS D:\CODE> django-admin startproject career
- 进入项目执行
django-admin startapp mbti
创建应用。
PS D:\CODE\career> django-admin startapp mbti
4. 添加应用到配置做关联
修改D:\CODE\career\career\setting.py
大约第41行,添加应用名称mbti
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mbti',//这里添加
]
5. 运行项目
使用Powershell运行python manage.py runserver 0.0.0.0:8001
,打开浏览器验证http://127.0.0.1:8001/
- 注意路径在 manage.py 的目录下
- 因为8000很可能已占用,所以修改了运行端口
PS D:\CODE\career> python manage.py runserver 0.0.0.0:8001
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
September 05, 2020 - 14:01:41
Django version 3.2, using settings 'career.settings'
Starting development server at http://0.0.0.0:8001/
Quit the server with CTRL-BREAK.
[05/Sep/2020 14:02:02] "GET / HTTP/1.1" 200 16351
[05/Sep/2020 14:02:02] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
6. 目录结构与运行图片
7. 可选安装virtualenv
PS D:\CODE> pip install virtualenv
Collecting virtualenv
Downloading virtualenv-20.0.31-py2.py3-none-any.whl (4.9 MB)
|████████████████████████████████| 4.9 MB 6.9 kB/s
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/appdirs/
Collecting appdirs<2,>=1.4.3
Downloading appdirs-1.4.4-py2.py3-none-any.whl (9.6 kB)
Collecting filelock<4,>=3.0.0
Downloading filelock-3.0.12-py3-none-any.whl (7.6 kB)
Requirement already satisfied: six<2,>=1.9.0 in c:\users\liguangliang\appdata\roaming\python\python37\site-packages (from virtualenv) (1.15.0)
Collecting importlib-metadata<2,>=0.12; python_version < "3.8"
Downloading importlib_metadata-1.7.0-py2.py3-none-any.whl (31 kB)
Collecting distlib<1,>=0.3.1
Downloading distlib-0.3.1-py2.py3-none-any.whl (335 kB)
|████████████████████████████████| 335 kB 6.8 kB/s
Collecting zipp>=0.5
Downloading zipp-3.1.0-py3-none-any.whl (4.9 kB)
Installing collected packages: appdirs, filelock, zipp, importlib-metadata, distlib, virtualenv
Successfully installed appdirs-1.4.4 distlib-0.3.1 filelock-3.0.12 importlib-metadata-1.7.0 virtualenv-20.0.31 zipp-3.1.0