How to make Django's devserver public ? Is it generally possible?

こ雲淡風輕ζ 提交于 2019-12-02 18:52:43

192.168.*.* is a LAN-private address -- once you've done the proper VMWare (or other VM manager) and firewall incantations to make it accessible from the LAN, it still won't be accessible from outside the LAN, i.e., from the internet at large (a good thing too, because such development servers are not designed for security and scalability).

To make some port of a machine with a LAN-private IP visible to the internet at large, you need a router with a "virtual servers" ability (many routers, even cheap ones, offer it, but it's impossible to be specific about enabling it since each brand has its own idiosyncratic way). I would also recommend dyndns or other similar service to associate a stable DNS name to your always-varying public IP (unless you're splurging for a static IP from your connectivity provider, of course, but the latter option is becoming costlier all the time).

superuser.com or serverfault.com may provide better answers and details (once you give every single little detail of your configuration in a question) since the question has nothing much to do with software development and everything to do with server administration and configuration.

python manage.py runserver 0.0.0.0:8181

This will run development server that should listen on all IP's on port 8181.

Note that as of Jun 17, 2011 Django development server is threaded by default (ticket #1609).

From docs:

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.

Assuming you have ruby installed, you just have to get localtunnel:

gem install localtunnel

then start your python development server with:

python manage.py runserver 0.0.0.0:8000

in another shell, start localtunnel:

localtunnel -k ~/.ssh/id_rsa.pub 8000 

That will output an url to access your local server.

Port 8000 is now publicly accessible from http://xxxx.localtunnel.com

That's it.

Already answered but adding npm alternate of same localtunnel

sudo npm install -g localtunnel

lt --port 8000 --subdomain yash

If you are using Virtualbox, You need to change the network setting in VB from "NAT" to "Bridged Adaptor". Then restart the linux. Now if you run sudo ifconfig you are able to see your IP address like 192.168.*.* . The last step is runserver

python manage.py runserver 192.168.*.*:8000

Cheers!

I had to add this line to settings.py in order to make it work (otherwise it shows an error when accessed from another computer)

ALLOWED_HOSTS = ['*']

then ran the server with:

python manage.py runserver 0.0.0.0:9595

You need to configure bridged networking in VMWare and also grant access to the target port in Ubuntu firewall.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!