2016-01-06 206 views
1

有点奇怪我无法从本地主机访问django,但我可以从本地IP访问它。Django无法从本地主机访问

python manage.py runserver 0.0.0.0:8000 

然后,当我尝试访问从

enter image description here enter image description here

我的主机文件

127.0.0.1 lmlicenses.wip4.adobe.com 
127.0.0.1 lm.licenses.adobe.com 
127.0.0.1 gc.kis.scr.kaspersky-labs.com ff.kis.scr.kaspersky-labs.com ie.kis.scr.kaspersky-labs.com 
0.0.0.0 gc.kis.scr.kaspersky-labs.com ff.kis.scr.kaspersky-labs.com ie.kis.scr.kaspersky-labs.com 

我猜了Windows防火墙或卡巴斯基做错事,但我不不知道该怎么做。

我已经添加例外端口8000和python.exe太

回答

1

我无法访问本地主机。

====

好了,我的解决方案现在是使用IPv6和端口8000是

python manage.py runserver [::]:8000 
1

刚刚尝试http://0.0.0.0:8000代替localhost:8000

默认localhost值为http://127.0.0.1

如果你看到runerver导致您有:

starting developement server at http://0.0.0.0:8000 

因为你说,在012 Django的服务器启动当您运行此命令:

python manage.py runserver 0.0.0.0:8000 
+0

这是一样的。我仍然无法甚至http://127.0.0.1:8000/访问也不http://0.0.0.0:8000/ –

+0

为什么哟想改变Django的服务器的IP地址?只需运行正常的命令'python manage.py runserver' @RichardOctovianus –

+0

'使用runserver 0.0.0.0:8000让它在Django官方文档中监听所有接口'https://code.djangoproject.com/ticket/396 –

0

只需执行

python manage.py runserver 

自动您可以通过本地主机访问并为EXTERN访问,你可以访问,如果不被它锁定8000端口,访问django管理员使用下一个网址:

http://127.0.0.1:8000/admin/ 
+0

只使用“python manage.py runserver”,我无法在浏览器中通过localhost:8000访问。这就是为什么我使用0.0.0.0:8000能够从我的LAN IP –

0

你的主机文件如何最终这样? 。你能测试一些东西吗?

# Copyright (c) 1993-2009 Microsoft Corp. 
# 
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows. 
# 
# This file contains the mappings of IP addresses to host names. Each 
# entry should be kept on an individual line. The IP address should 
# be placed in the first column followed by the corresponding host name. 
# The IP address and the host name should be separated by at least one 
# space. 
# 
# Additionally, comments (such as these) may be inserted on individual 
# lines or following the machine name denoted by a '#' symbol. 
# 
# For example: 
# 
#  102.54.94.97  rhino.acme.com   # source server 
#  38.25.63.10  x.acme.com    # x client host 

# localhost name resolution is handled within DNS itself. 
# 127.0.0.1  localhost 
# ::1    localhost 

我的主文件看到一切都被注释掉了。你可以用你的hosts file做同样的事情吗?从我的浏览器8000,如果我跑python manage.py runserver

我不知道为什么这个命令不能在我的笔记本电脑工作,但在我的电脑,它就可以工作:

+0

访问似乎无关hosts文件,我清楚我的情况下,它也试过它 –

+0

之前。 –

0

settings.py文件在项目文件夹, 添加'0.0.0.0'允许主机列表。 然后保存该文件并运行该命令。猜测将工作。

0

我也初学者到Django的,但我需要下面的东西来运行服务器:

  1. settings.py,加入ALLOWED_HOSTS
    ALLOWED_HOSTS = [ 'elearning.com' ]
    其中elearning.com是我的主机名。您可以使用逗号分隔多个主机。
  2. 使用下面的命令来运行服务器:
    python manage.py runserver [::]:8000

    python manage.py runserver 0.0.0.0:8000

    python manage.py runserver 0:8000
    它现在将监听所有接口。阅读Django文档here
  3. 浏览到给定的主机名。就我而言,这是http://elearning.com:8000/

我试着写ALLOWED_HOSTS IP,但它没有工作,我无法打开浏览器http://192.168.x.x:8000。任何人都可以请纠正我?