21

I have a django app on my local computer. I can access the application from a browser by using the url: http://localhost:8000/myapp/

But I cannot access the application by using the ip of the host computer: http://193.140.209.49:8000/myapp/ I get a 404 error.

What should I do? Any suggestions?

2 Answers 2

70

I assume you're using the development server. If so, then you need to specifically bind to your external IP for the server to be available there. Try this command:

./manage.py runserver 193.140.209.49:8000
Sign up to request clarification or add additional context in comments.

4 Comments

Or you can use 0.0.0.0:8000 to bind to the computer's external IP address whatever it is.
0.0.0.0:8000 binds to all interfaces, not just the external one, so it can still be accessed as localhost:8000
0:8000 also works, as a shorter spelling of 0.0.0.0:8000.
@EdwardDale it works fine but after that I can only access my server using system IP and if I trying to access using localhost so server not responding.
0

I had a similar issue. In my case, I had to do as below:

  • To run App in Local LAN *
python manage.py runserver 0.0.0.0:8000
http://localhost:8000
http://127.0.0.1:8000
http://192.168.0.99:8000
  • To run App with Public IP *

Port 8080 would not work for me and so I had to add Port 8081.

Add port 8081 in Windows Defender (Inbound Rules)

Add port 8081 in the Internet Router's Virtual Servers

python manage.py runserver 0.0.0.0:8081
http://103.122.xxx.xx:8081

settings.py

ALLOWED_HOSTS = ['127.0.0.1', 'localhost', '103.122.xxx.xx', '192.168.0.99']

I am sure that there could be a better method. As of now this works for me in Visual Studio Code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.