Py学习  »  问与答

django 官方 turtorial 关于本地主机的一个问题

kxx1309 • 9 年前 • 2502 次点击  

大家好,小弟最近刚开始学习django,所以打算从官方文档开始学起,但是在第一部分的开发服务器部分(https://django-18-docs.readthedocs.org/zh_CN/latest/intro/tutorial01.html),当我在虚拟机中执行命令 python manage.py runserver 时,没有显示出错,但是我在网页中输入 127.0.0.1:8000时却显示'网页无法显示', 网上搜索了很多,折腾了老半天,但始终没能找到有效地解决办法。 希望大家能给点建议和帮助,感激不尽!

现在已经尝试的办法: 1 关闭防火墙 2 修改proxy 设置 3 修改etc/hosts 并向其添加domain/host 4 修改虚拟机中的操作系统

已找到解决办法: 在命令行中输入 python manage.py runserver 0.0.0.0:8000 具体不知道为什么,但是问题这样就解决了

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/1247
 
2502 次点击  
文章 [ 1 ]  |  最新文章 9 年前
shen_gan
Reply   •   1 楼
shen_gan    9 年前

你在虚拟机中输入 127.0.0.1:8000 访问,只能在虚拟机中使用浏览器访问。0.0.0.0 是指允许其他主机(ip)访问你的虚拟机。

附上官网一句话:

Note that the default IP address, 127.0.0.1, is not accessible from other machines on your network. To make your development server viewable to other machines on the network, use its own IP address (e.g. 192.168.2.1) or 0.0.0.0 or :: (with IPv6 enabled).