Accessing django project in LAN systems

2020-05-23 08:34发布

问题:

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))

回答1:

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. :)



回答2:

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)