项目结构 - setting.py
1.setting.py包含了django项目启动的所有配置项
2.配置项分为公有配置和自定义配置
配置项格式例:BASE_DIR='XXX'
公有配置 -django官方提供的基础配(http://docs.djangoproject.com/en/2.2/ref/settings)
3.DEBUG = True为开发模式,报错页面会有相应说明解析
DEBUG = Faulse为上线模式
4.ALLOWED_HOSTS
式例:如果要在局域网其他主机也能访问此主机的django服务,启动方式如下:
python3 manage.py runserver 0.0.0.0.5000
^C(venv) appledeMacBook-Pro:mysite1 apple$ python3 manage.py runserver 0.0.0.0:5000
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.
August 05, 2021 - 03:43:21
Django version 3.1.13, using settings 'mysite1.settings'
Starting development server at http://0.0.0.0:5000/
Quit the server with CONTROL-C.
然后另开一个终端,输入命令:“ifconfig”
得到内网ip ,然后通过内网ip+‘:5000’,即192.168.31.138:5000访问浏览器,会出现页面提示
只要按照提示要求将IP添加到‘ALLOWED_HOSTS = [ ]’即可
ALLOWED_HOSTS = ['192.168.31.138']
指定网络设备如果内网环境下其他主机想正常访问该站点,需要加ALLOWED_HOSTS=['内网ip']