对LAN上托管的Django的Http请求超时

时间:2019-01-25 03:32:00

标签: django rest django-rest-framework web-hosting

我想将Django rest-api托管在本地服务器上,以便托管网站的访问者可以对其进行调用。它可以在localhost:8000上完美运行。

我所做的是:

我将settings.py文件中的ALLOWED_HOSTS更改为所有['*']

python3 manage.py runserver 0:8000

但是现在,当我尝试拨打电话或访问http://IP:8000/时,我得到了:

(quizkly_env) DN0a22641a:web shiningsunnyday$ http --json POST http://IP:8000/quizkly/ content="Barack Obama was the 44th president of the United States."

http: error: Request timed out (30s).
(quizkly_env) DN0a22641a:web shiningsunnyday$ 

我也尝试过

python3 manage.py runserver IP:8080

但是得到了:

System check identified no issues (0 silenced). 
January 25, 2019 - 03:28:56 Django version 2.1.5, using settings 'quizkly.settings' 
Starting development server at http://IP:8080/
Quit the server with CONTROL-C.
Error: That IP address can't be assigned to.

怎么了?

1 个答案:

答案 0 :(得分:0)

您需要在网络中运行它

python3 manage.py runserver 0.0.0.0:8000

在与之连接的服务器上,使用IP