简体   繁体   中英

Http request to Django hosted on LAN timed out

I want to host my Django rest-api on my local server so visitors to my hosted website can make calls to it. It works perfectly on localhost:8000.

What I did was:

I changed ALLOWED_HOSTS in my settings.py file to all ['*']

python3 manage.py runserver 0:8000

But now when I try to make a call to or visit http://IP:8000/ I get:

(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$ 

I also tried

python3 manage.py runserver IP:8080

but got:

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.

What's going wrong?

You need to run it in your network

python3 manage.py runserver 0.0.0.0:8000

And on the server your connecting to it with, use the IP

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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