Allow locally hosted Django App Access over WAN

103 Views Asked by At

I am currently working on developing a webapp and working with a partner on the other side of the state. I would like to allow them to access the webapp for testing and development purposes but cant seem to be able to figure out how to get the connection working. I have enabled port forwarding for port 8000 and have already attempted to run the server using my local IPv4 address. I can connect via LAN, but my partner cannot connect through their browser. We already have an established MySQL connection and all we had to do was forward port 3306 and use my router IP for WAN but that does not seem to be working for Django. Any suggestions on getting this working?

2

There are 2 best solutions below

1
On

There are two cases, (a) you have a public IP address (b) you do not have a public IP address.

I will try to give solutions for both.

  1. For sharing a local django development server you first need to allow the hosts. We have to tell Django it's OK to allow requests from your public IP / a tunnel if you do not have a public ip.

    To do that, edit the settings.py file. If you have a public IP like x.x.x.x add that to ALLOWED_HOSTS list as

    ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'x.x.x.x']
    

    If you do not have a public IP, you can use a tunneling service like https://pinggy.io or https://zrok.io or ngrok to ge a public URL. Allow that particular service like:

    ALLOWED_HOSTS = ['localhost', '127.0.0.1', '.pinggy.io']
    
  2. Now run your development server. By default it runs on port 8000.

  3. If you have a public IP address, ensure your firewalls allow connections to port 8000, or your router has port forwarding configured properly. You can test with a test server instead of django like running python -m http.server and accessing it.

  4. If you do not have a public IP, just start a tunnel. Using https://pinggy.io you can do it with the following command: ssh -p 443 -R0:localhost:8000 a.pinggy.io which will give you a public URL.

0
On

The issue does not seem to be directly related to Django, but more to network issues. Without more details, it's hard to troubleshoot.

Instead of opening your ports, a simpler solution might be to use a tunneling service, like ngrok, expose.dev or localtunnel.

This solution does not required you to mess with network, firewall or DNS settings, and usually has the added benefit of adding HTTPS.