学习笔记,仅供参考
本系列Blog以应用为主,理论基础部分我在后端专栏的Django系列博客已经写过了,如果有些需要补充的知识点,我会在这个系列中,尽量详细的写一下。
进入要存放项目的目录:
cd F:\MyStudio\PythonStudio\goatbishop.project01\Django创建一个项目:
django-admin startproject [项目名称] #比如 django-admin startproject newwebsite1 进入新创建的项目(newwebsite1)进入项目文件:
cd newwebsite1查看项目文件夹下的文件:
dir #输出 2020/07/01 12:16 <DIR> . 2020/07/01 12:16 <DIR> .. 2020/07/01 12:16 652 manage.py 2020/07/01 12:16 <DIR> newwebsite1 1 个文件 652 字节 3 个目录 26,557,247,488 可用字节 运行该项目 python manage.py runserver #输出 Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). You have 17 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. July 01, 2020 - 12:34:28 Django version 2.2.13, using settings 'newwebsite1.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK.默认监听8000端口。
在浏览器中向http://127.0.0.1:8000/发起请求 指定端口号为5000开启服务 python manage.py runserver 5000 #输出 Performing system checks... System check identified no issues (0 silenced). You have 17 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. July 01, 2020 - 12:39:53 Django version 2.2.13, using settings 'newwebsite1.settings' Starting development server at http://127.0.0.1:5000/ Quit the server with CTRL-BREAK. 更改ip地址如果我们网站的IP地址为127.0.0.1,那么只有我们自己的电脑可以访问这个项目,别人是访问不到的,如果我想要别人(同一个局域网下)也可以访问,就需要指定IP地址为0.0.0.0
python manage.py runserver 0.0.0.0:8000在项目文件夹下的settings.py中修改允许访问的域名ALLOWED_HOSTS:
ALLOWED_HOSTS = ['*'] #或者是别人的ip地址这样别人的电脑就可以访问我们的项目了(注意要关闭防火墙)。