2016-01-06 379 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。任何人都可以請糾正我?