Django start
- $
python manage.py runserver
或 - $
python3 manage.py runserver
windows上的python3版本的实用程序是python,而linux/mac平台上是python3 - 项目访问:http://127.0.0.1:8000
Warning
You have 15 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.
原因:是在配置文件 setting.py中默认开启了数据库sqlite的连接
Fix it
方式一: 按提示信息操作
- $
python manage.py migrate
或 - $
python3 manage.py migrate
方式二:
- control/command + c 结束服务
- 在manage.py中注释掉两行如下:
DATABASES = { 'default': { # 'ENGINE': 'django.db.backends.sqlite3', # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } }
Support remote visits
-
更改启动方式 $
python manage.py runserver 0:8000
注 使用python或python3根据不同平台选择 -
查找自己的ip地址:mac 上通过 ifconfig 查找, windows 上通过 ipconfig 查找
-
然后在配置文件中, 添加自己的ip地址如下:
ALLOWED_HOSTS = ['192.168.1.105'] # 或直接用 '*'
-
验证访问://192.168.1.105:8000