python版本:2.7.14
◆ 下载两个包:
1、Django-1.11.12.tar.gz
解压-->python setup.py install
2、pytz-2018.4-py2.py3-none-any.whl
pip install pytz-2018.4-py2.py3-none-any.whl
或者直接使用pip命令:
pip install django
◆ 创建工程:
D:\>django-admin.exe startproject mysite
◆ 启动工程:
D:\>cd mysite
#D:\mysite>python manage.py runserver 127.0.0.1:8001 #此处可以指定IP和端口python manage.py runserver 10.20.113.146:8001
D:\mysite>python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
You have 13 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.
April 13, 2018 - 21:39:34
Django version 1.11.12, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[13/Apr/2018 21:39:43] "GET / HTTP/1.1" 200 1716
Not Found: /favicon.ico
[13/Apr/2018 21:39:43] "GET /favicon.ico HTTP/1.1" 404 1962
1、挂后台运行:
nohup python manage.py runserver 127.0.0.1:8001 &
2、启动异常处理:
异常信息:
ModuleNotFoundError: No module named '_sqlite3'
处理方法:
原因:安装python的时候没有找到sqlite3.so的库。
# 安装sqlite相关的全部,可能并不需要全部,为了简单直接用*号代替了
yum install sqlite*
然后重新编译python或者重新安装python
◆ 验证:
登陆:http://127.0.0.1:8000/
1、验证异常处理:
异常信息:
Invalid HTTP_HOST header: '192.168.1.111:8000'. You may need to add '192.168.1.111' to ALLOWED_HOSTS
处理方法:
在我们创建的项目里修改setting.py文件
ALLOWED_HOSTS = ['*'] #在这里请求的host添加了*
◆ 创建APP:
在工程目录下执行如下命令
python manage.py startapp app01