Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making django server accessible in LAN

Tags:

python

django

I have installed Django server and it can be accessed as below

http://localhost:8000/get-sms/
http://127.0.0.1:8000/get-sms/

suppose My IP is x.x.x.x .

From another PC under the same network when I do

my-ip:8000/get-sms/

but it is not working.

I can easily ping my IP with that computer.

Moreover, on my port 81, I have apache, which is easily accessible like below

http:///my-ip:81

What can be the issue? Do I need something extra in Django

like image 510
sumit Avatar asked Mar 03 '14 10:03

sumit


People also ask

How do I run a Django server on another port?

Inside the commands folder open up the runserver.py script with a text editor. Find the DEFAULT_PORT field. it is equal to 8000 by default. Change it to whatever you like DEFAULT_PORT = "8080"


3 Answers

Running the Django Development Server
This is what you're looking for. To help you further, here is what you should do:

python manage.py runserver 0.0.0.0:8000

By the way, this may be a duplicate of this question.

Here is what the documentation says:

Note that the default IP address, 127.0.0.1, is not accessible from other machines on your network. To make your development server viewable to other machines on the network, use its own IP address (e.g. 192.168.2.1) or 0.0.0.0.

like image 198
Depado Avatar answered Oct 14 '22 09:10

Depado


To add to @Depado 's answer you may need to add your LAN IP address to ALLOWED_HOSTS in the settings.py along with localhost. it would look like,

ALLOWED_HOSTS = ["localhost", "192.168.8.160"]

(if localhost isn't working use 127.0.0.1 as suggested by @Sabito 錆兎)

like image 28
Achala Dissanayake Avatar answered Oct 14 '22 09:10

Achala Dissanayake


You can use https://ngrok.com/ this will expose your local web server to the internet/public.

like image 3
Venkatesh Bachu Avatar answered Oct 14 '22 09:10

Venkatesh Bachu