本地Django网站不会在浏览器中加载 [英] Local Django website won't load in browser

查看:153
本文介绍了本地Django网站不会在浏览器中加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我猜想有一个非常简单的解决方案,但是我搜索了每个论坛和设置指南,但找不到答案:

I'm guessing there's a very simple solution to this, but I searched every forum and setup guide and can't figure it out:

我在 local 服务器上(使用VirtualBox和Vagrant)构建了一个Django/CentOS-6.3环境.当我在"vagrant"终端中使用"python manage.py runserver [::]:8000"启动服务器时,它没有任何错误.

I built a Django/CentOS-6.3 environment on my local server (using VirtualBox and Vagrant). When I startup my server in the vagrant terminal with 'python manage.py runserver [::]:8000' it starts up with no errors.

Validating models...

0 errors found
May 31, 2013 - 13:56:15
Django version 1.5.1, using settings 'mysitename.settings'
Development server is running at http://[::]:8000/
Quit the server with CONTROL-C.

但是,当我尝试在浏览器中导航到"http://127.0.0.1:8001"时(我在V​​agrantfile中设置了从端口8000到端口8001的端口转发),浏览器只会挂起5分钟直到超时,然后挂起返回消息:

However, when I try to navigate to 'http://127.0.0.1:8001' in my browser (I set up port forwarding from port 8000 to port 8001 in my Vagrantfile), the browser just hangs for 5 minutes until it times out, then it returns the message:

> The connection was reset 
> The connection to the server was reset while the page was loading. 
> ...

这是我关闭本地服务器后从浏览器中获得的完全相同的消息.我的计算机显然将其识别为转发端口,因为我尝试使用的任何其他端口(例如8000)都会立即返回错误,表明它无法以127.0.0.1:8000建立与服务器的连接.

This is the exact same message I get from the browser even after I shut down my local server. My computer obviously recognizes this as a forwarded port, because any other port I try (such as 8000) instantly returns an error saying that it can't establish a connection to the server at 127.0.0.1:8000.

关于服务器文件,我过去在Django/Ubuntu上进行过许多类似的设置,并且从未遇到过任何问题,但是Django/CentOS一定与众不同,这导致了这种情况的发生(或者也许我在我的一个服务器文件中犯了一个错误).我遵循了有关设置Django&的指南. PostgreSQL也可以在CentOS上使用,但无济于事.我将在下面评论一些我创建/编辑的文件.

With regard to the server files, I have done many similar setups with Django/Ubuntu in the past and have never had any issues, but there must be something different about Django/CentOS that is causing this to happen (or maybe I made a mistake someone in one of my server files). I have followed guides for setting up Django & PostgreSQL on CentOS, too, but to no avail. I'll comment some of the files I have created/edited below.

如果有人有解决方案,或者甚至有关于从哪里开始寻找错误的建议,我将非常感谢.

If anyone has a solution, or even has advice on where to start looking for errors, I would very much appreciate it.

推荐答案

如果您的网络配置正确,并且django应用程序具有

If your network is configured correctly and your django application with

python manage.py runserver 0.0.0.0:8000

python manage.py runserver 0.0.0.0:8000

,并且您仍然无法从VM主机访问django应用,几乎可以肯定存在防火墙问题.如果您正在运行iptables,则上述解决方案很好.

and you still can't access your django app from the VM host there is almost certainly a firewall issue. The solution above is good if you are running iptables.

我从Windows 7主机在virtualbox VM上部署了CentOS 7.我不知道此发行版使用Firewalld而不是iptables来控制访问.

I deployed CentOS 7 on a virtualbox VM from a Windows 7 host. I didn't know that this distribution uses firewalld, not iptables to control access.

如果

ps -ae | grep防火墙

ps -ae | grep firewall

返回类似

602? 00:00:00 Firewalld

602 ? 00:00:00 firewalld

您的系统正在运行firewalld,而不是iptables.它们不能一起运行.

your system is running firewalld, not iptables. They do not run together.

要更正您的VM,以便可以从主机访问django站点,请使用以下命令:

To correct you VM so you can access your django site from the host use the commands:

firewall-cmd --zone = public --add-port = 8000/tcp --permanent

firewall-cmd --zone=public --add-port=8000/tcp --permanent

firewall-cmd-重新加载

firewall-cmd --reload

非常感谢pablo v在访问虚拟机上的django服务器"一文中指出了这一点.

Many thanks to pablo v for pointing this out in the post "Access django server on virtual Machine".

这篇关于本地Django网站不会在浏览器中加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆