无聊的IT

导航

虚拟机 django 端口无法连接

我的虚拟机django服务器为192.168.27.100,使用启动命令python manage.py runserver 9001启动后,发现笔记本电脑的游览器无法连接

python@qinhan MyCrazyeyes]$ python manage.py runserver 9001
Performing system checks...

System check identified no issues (0 silenced).
March 13, 2018 - 17:35:47
Django version 2.0.1, using settings 'MyCrazyeyes.settings'
Starting development server at http://127.0.0.1:9001/
Quit the server with CONTROL-C.
Performing system checks...

 

经过百度发现首先要view settings.py ,将ALLOWED_HOSTS改为*

[python@qinhan MyCrazyeyes]$ view settings.py 

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '%7noe(d-i*qxjunhtg(bg8+rkyd3yzelz&3m-o3^_1*d!i04!f'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'web',
]

 

随后启动命令必须用ip+端口方式启动

^C[python@qinhan MyCrazyeyes]$ python manage.py runserver 192.168.27.100:9001
Performing system checks...

System check identified no issues (0 silenced).
March 13, 2018 - 17:43:35
Django version 2.0.1, using settings 'MyCrazyeyes.settings'
Starting development server at http://192.168.27.100:9001/
Quit the server with CONTROL-C.

 

 这样就可以访问了

 

posted on 2018-03-15 06:52  秦寒  阅读(338)  评论(0编辑  收藏  举报