Accessing django project in LAN systems [duplicate]
Asked Answered
E

4

19

I used django and developed a site which is working fine, and its about to move to production and ready for deployment in a couple of weeks.

So before moving to production, i want to share the site with some of my employees to check the functionality and something else. Actually their systems are connected in LAN with mine.

So my system IP address is something like 192.168.12.135, when we run run django development server its runs at localhost:8000, i mean with the system IP address and with a port 8000 like 192.168.12.135:8000 right.

So i had shared them the project site link as 192.168.12.135:8000, but when they tried on the systems which are connected in LAN, it is not accessible and displaying an error Server not found.

I tried the above same way because recently i used python web.py framework and developed a minimal site , and when we run the server, it by default runs as localhost:8080 , and when i accessed this link from others system that are connected in LAN with mine as 192.168.12.135:8000 , its working fine and is accessible.

So can anyone please let me know

1. How to access the site on the systems that are connected in LAN before moving to production(in some real servers like apache, nginx etc.,).

2. Basically i am new to web developing and this is my first site developed in python, so
   i don't know more about servers and deploying a project. So can anyone please let me know   
   the detailed information about deploying django on different servers

(First of all i am looking for a solution for 1st problem(Accessing in LAN before moving to production))

Eo answered 18/3, 2013 at 6:51 Comment(0)
S
36

You need to explicitly tell the development server to run on your IP rather than localhost.

Try python manage.py runserver your_ip:port.

Though it'll be accessible if you're running through apache or any other webservers other than the development server.

And to your 1st question, I would advice you to host and use a local apache server rather than using development server. Doing so, you can foresee the issues you'll be facing when moving to production.

And to 2nd, there are plenty of resources available configuring Django with different servers. Hail Google. :)

Sainthood answered 18/3, 2013 at 6:55 Comment(2)
thanks that helped, actually i am looking for a quick deploying tutorial that a beginner can deploy very easilyEo
If you found my answer helpful, mark it as right. I should admit that it's bit of complex task for a newbie. May be you should get help from the sys-admin team. And for you, google.co.in/…Sainthood
P
38

If you run

python manage.py runserver 0.0.0.0:8000

your development server will be available on port 8000 to anyone on your LAN and on localhost as well (and it does not depend on your ip address)

Phyllida answered 18/3, 2013 at 9:11 Comment(2)
This doesn't work for me on devices other than the computer I'm actually running the server on. The browser just says that it can't connect to the server on other devicesDamnatory
in settings.py you need to add the hostname in ALLOWED_HOSTS, if you are accessing the server using macbook1.local:8000 then add that so you can access it from your phone or another computer. for example: ALLOWED_HOSTS = ['macbook1.local'] (tested in django 1.10, macbook, and iphone)Originate
S
36

You need to explicitly tell the development server to run on your IP rather than localhost.

Try python manage.py runserver your_ip:port.

Though it'll be accessible if you're running through apache or any other webservers other than the development server.

And to your 1st question, I would advice you to host and use a local apache server rather than using development server. Doing so, you can foresee the issues you'll be facing when moving to production.

And to 2nd, there are plenty of resources available configuring Django with different servers. Hail Google. :)

Sainthood answered 18/3, 2013 at 6:55 Comment(2)
thanks that helped, actually i am looking for a quick deploying tutorial that a beginner can deploy very easilyEo
If you found my answer helpful, mark it as right. I should admit that it's bit of complex task for a newbie. May be you should get help from the sys-admin team. And for you, google.co.in/…Sainthood
M
4

In your settings.py change ALLOWED_HOSTS to

ALLOWED_HOSTS = ['*']

Run your server by entering the following command

python manage.py runserver 0.0.0.0:8000

In order to access the project from another device enter the IP address of the server followed by the port number, which is 8000 in this example.

Marbut answered 9/8, 2020 at 14:3 Comment(0)
N
3

On windows I did everything you said but one thing was missing at my end to connect through Wi-Fi..

In settings.py:

ALLOWED_HOST = ['*']

Put Network profil in Private mode:

Windows > Settings > Network & Internet > Wi-Fi > (Click on_your_network) > In Network profil select: Private

Exemple: Run your server on the port 8000:

python manage.py runserver 0.0.0.0:8000

Then to access to the server with your other devices connected to the same network, enter the IPv4's server address with the your port (here 8000)

Exemple, if the IPv4's server address is 192.168.20.26 put the folling text directly in your browser:

192.168.20.26:8000
Naominaor answered 28/3, 2022 at 11:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.