How to share localhost port over local network [duplicate] - django

This question already has answers here:
Making django server accessible in LAN
(4 answers)
Closed 1 year ago.
I created webpage on local server with django framework (python). I have acces to it under address http://localhost:8000/. Now I want to share it over local network. I try to do it with Windows firewall Inbound/outbound rules, but it seems either I do something wrong or it's not enough.

To access a Django project running on a local network, you have to runserver with 0.0.0.0 as IP
python manage.py runserver 0.0.0.0:8000
and then set
ALLOWED_HOSTS = ["localhost", "yours_host_ip_aaddress"]
that should work if your firewall allows!

I am not sure how to suggest a duplicate question, but seems your question have an answer here. Basically, you need to ask the django program to accept connection from the outside world by
python manage.py runserver 0.0.0.0:8000

Related

some advices on deploying Django app to product locally

I want to deploy (production not testing) Django app with PostgreSQL database for my company, however, for security reason I want the app to be on local network and not accessible through the internet. I need some recommendations and advices to achieve that on setup and tools.
Suppose I know python3 manage.py runserver 0.0.0.0:8000
EDIT: I wanted to be accessible by different machine on the same network.
You can just use command:
python3 manage.py runserver 8080
The default bind ip is 127.0.0.1, it can be only be access from your local network but not from the internet.
By default when you will runserver it will run on 127.0.0.1. And that will only be visible to your computer only
You have to do about two changes
First of all get your ip address of your local lan network by ipconfig command(in ubuntu). you can search other command to detect ip of your local lan network on your own
Let say your network ip is 192.168.0.100
Now go to settings.py
change ALLOWED_HOSTS=[] to
ALLOWED_HOSTS = ['192.168.0.100']
Now run
python3 manage.py runserver 0.0.0.0:8000
It will visible to all your clients connected on that network
They just have to type this url
192.168.0.100:8000
to see the website

app running on django dev server inaccessible from network computer

How do I access an app running on django dev server(ubuntu 15.10) from another machine on the same network(eg. a windows 7) ?
I am able to ping this machine from another network computer.
"python manage.py runserver 0.0.0.0:8000" - does not allow me to access the app from another network computer.
app uses django 1.5.9
https://docs.djangoproject.com/en/1.8/ref/django-admin/#django-admin-runserver
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 or :: (with IPv6 enabled).
runserver 0.0.0.0:8000
Make sure you open port 8000
python manage.py runserver 0.0.0.0:8000
is ok but you have to also modify settings.py of your app. You need to change ALLOWED_HOSTS.
For example put * to allow access for everybody or put only certain IPs to limit access:
ALLOWED_HOSTS = ['*']
more answers here:
CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False

How to run Django app from lan using development server

I know that this question has been already asked but the answers didn't help me.
I ran the command python manage.py runserver 0.0.0.0:8000 and
now the site is accessible from the computer using localhost:8000 but how can i run it on other devices connected to the local wifi network ?
This is a network question: localhost is an alias for your local IP 127.0.0.1.
You can start Django server on an another address as following:
python manage.py runserver 192.168.100.1:8080
Where 192.168.100.1 is your IP on local network. See official commands' docs for more details.

Local Django website won't load in browser

I'm guessing there's a very simple solution to this, but I searched every forum and setup guide and can't figure it out:
I built a Django/CentOS-6.3 environment on my local server (using VirtualBox and Vagrant). When I startup my server in the vagrant terminal with 'python manage.py runserver [::]:8000' it starts up with no errors.
Validating models...
0 errors found
May 31, 2013 - 13:56:15
Django version 1.5.1, using settings 'mysitename.settings'
Development server is running at http://[::]:8000/
Quit the server with CONTROL-C.
However, when I try to navigate to 'http://127.0.0.1:8001' in my browser (I set up port forwarding from port 8000 to port 8001 in my Vagrantfile), the browser just hangs for 5 minutes until it times out, then it returns the message:
> The connection was reset
> The connection to the server was reset while the page was loading.
> ...
This is the exact same message I get from the browser even after I shut down my local server. My computer obviously recognizes this as a forwarded port, because any other port I try (such as 8000) instantly returns an error saying that it can't establish a connection to the server at 127.0.0.1:8000.
With regard to the server files, I have done many similar setups with Django/Ubuntu in the past and have never had any issues, but there must be something different about Django/CentOS that is causing this to happen (or maybe I made a mistake someone in one of my server files). I have followed guides for setting up Django & PostgreSQL on CentOS, too, but to no avail. I'll comment some of the files I have created/edited below.
If anyone has a solution, or even has advice on where to start looking for errors, I would very much appreciate it.
If your network is configured correctly and your django application with
python manage.py runserver 0.0.0.0:8000
and you still can't access your django app from the VM host there is almost certainly a firewall issue. The solution above is good if you are running iptables.
I deployed CentOS 7 on a virtualbox VM from a Windows 7 host. I didn't know that this distribution uses firewalld, not iptables to control access.
if
ps -ae | grep firewall
returns something like
602 ? 00:00:00 firewalld
your system is running firewalld, not iptables. They do not run together.
To correct you VM so you can access your django site from the host use the commands:
firewall-cmd --zone=public --add-port=8000/tcp --permanent
firewall-cmd --reload
Many thanks to pablo v for pointing this out in the post "Access django server on virtual Machine".
the host's "127.0.0.1" is not the same as the guest's "127.0.0.1". Per default the command
python manage.py runserver
listens only to the guest's localhost. You should be able to test it from within the vm (use "vagrant ssh" to login) and run
curl -I http://127.0.0.1:8000/
The host as a different IP. To access the development server from the host you have to start it without ip restriction:
python manage.py runserver 0.0.0.0:8000
Yes:
python manage.py runserver [::]:8000
should be the same. But that's IPv6 syntax AFAIK. Are you sure that the "manage.py runserver" command supports IPv6 by default? I've never used ipv6 addresses w/ django, but looking at the source (https://github.com/django/django/blob/master/django/core/management/commands/runserver.py) there seams to be a flag that the default to False ("--ipv6"). Perhaps that's the "real" problem?
Regards,
For a similar problem,
This command worked like a charm for me
python manage.py runserver [::]:8001
Check your iptables, and stop it. Ubuntu commonly does not open the iptables when it starts.

Django on SSH public IP

I have Django installed on my SSH-server. But the SSH-server I'm working on, is not at my home. So the local ip-adres Django creates (127.0.0.0:8000) isn't available for me, I can't test my Django-apps graphicly.
What could be a Solution to get it work?
Djano has a command runserver that could set the IP-adres of the server like this:
django-admin.py runserver [IP]:[port]
But which IP I have to fill in there to make it work? The only IP I have is the IP of the SSH-server. Isn't it possible to fill in the IP-address of my webhost(but where I need to give in password etc)?
Thanks a lot!
Choose a publicly available port (say 8000), or redirect an existing web server to use the port you choose, and then start with
django-admin.py runserver 0.0.0.0:8000
Edit
If you happen not to control your available ports, you probably need to hook apache in front of your app. See https://docs.djangoproject.com/en/1.3/howto/deployment/modwsgi/ for info on how to deliver your app with apache and mod_wsgi.
You can try Putty with its tunnels. This program for windows, but I think you can find it for Linux if you use it. I used it to get access to my Postgres databse with pgAdmin with this article. So you can use tunnel for 8000 port and program to get access to it on your local machine.