简体   繁体   English

如何修复Django中的连接错误

[英]How to fix the connection error in django

I have created a new project in django. 我在Django中创建了一个新项目。 when I run python manage.py runserver , I am getting the msg in command prompt like below. 当我运行python manage.py runserver时 ,我在如下所示的命令提示符中得到了味精。

 /var/www/samplepro/myapp$ python manage.py runserver
 Performing system checks...

 System check identified no issues (0 silenced).
 March 26, 2015 - 10:52:31
 Django version 1.7.7, using settings 'myapp.settings'
 Starting development server at http://127.0.0.1:8000/
 Quit the server with CONTROL-C.

when I test in browser, I am getting the page can't be displayed error. 在浏览器中测试时,出现页面无法显示错误。 Can anyone help me to do get the django page. 任何人都可以帮助我获取django页面。

You stated that you are running the server on Ubuntu while you are trying to connect it from another PC running Windows. 您表示正在尝试从另一台运行Windows的PC连接Ubuntu时在Ubuntu上运行服务器。 In that case, you should replace the 127.0.0.1 with the actual IP address of Ubuntu server (the one you use for PuTTY). 在这种情况下,应将127.0.0.1替换为Ubuntu服务器的实际IP地址(用于PuTTY的IP地址)。

I am also developing in a virtual machine. 我也在虚拟机中进行开发。

Use ifconfig to figure out the IP address that has been assigned to your virtual machine. 使用ifconfig找出已分配给您的虚拟机的IP地址。

Then start the server with: 然后使用以下命令启动服务器:

python manage.py runserver <IP>:8000

Of course you could also use a different port instead of 8000 . 当然,您也可以使用其他端口代替8000 Then use that address and port in your host browser to access your server. 然后在主机浏览器中使用该地址和端口访问服务器。

Note: At least in my VM, the virtual machine gets a new address from time to time, so check that in case you have trouble starting your server with the same command. 注意:至少在我的VM中,虚拟机会不时获取新地址,因此请检查以防在使用同一命令启动服务器时遇到麻烦。

If this does not help, check your hosts file as mentioned in one of the comments. 如果这样做没有帮助,请按照注释之一中所述检查主机文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM