25

I am developing a web application on my local computer in Django.

Now I want my webapp to be accessible to other computers on my network. We have a common network drive "F:/". Should I place my files on this drive or can I just write something like "python manage.py runserver test_my_app:8000" in the command prompt to let other computers in the network access the web server by writing "test_my_app:8000" in the browser address field? Do I have to open any ports and how can I do this?

Kara
  • 6,115
  • 16
  • 50
  • 57
Jamgreen
  • 10,329
  • 29
  • 113
  • 224

7 Answers7

32

It is should be done with central system or server.

By default manage.py runserver will not give ip bind permission. So

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

If you want to check in your local machine then follow

python manage.py runserver 0.0.0.0:8000

Now go to your network computer and access your ip like 192.168.1.24:8000

Updated:

For Django version about 1.10 you should add your host to ALLOWED_HOSTS here

Community
  • 1
  • 1
Raja Simon
  • 10,126
  • 5
  • 43
  • 74
  • I use the ip given at http://whatismyipaddress.com/ but when I run `python manage.py runserver xxxxxxx:8000` it says "Error: That IP address can't be assigned-to.". – Jamgreen Aug 28 '14 at 13:54
  • 2
    do Not use global IP. Just type manage.py runserver 0.0.0.0:8000 and go to `run` > `cmd` > `ipconfig` | ip4 address. – Raja Simon Aug 28 '14 at 13:56
  • 1
    Okay :-) I can access it on my own computer. I will check if I can access it on another computer on the network in a minute. Thank you! – Jamgreen Aug 28 '14 at 14:28
  • Hi rajasimon. I cannot access it on other computers. Do I need to open a port or something? – Jamgreen Aug 28 '14 at 15:02
  • @Jamgreen: We can't know if you have to "open a port". It is your network so you should know what's going on. – Matthias Aug 28 '14 at 15:45
  • How many users will be accessing this? If it's more than one at a time then using the development server is not a good idea. – cms_mgr Aug 28 '14 at 15:52
  • No it's not working :( It's a work network and I don't know which firewalls are being used. There will be around 5-10 users at the same time. Can I install a small server without having admin rights on the network? – Jamgreen Aug 28 '14 at 16:28
  • Can I somehow see if it's the firewall that are causing the problem? Going to my system administrator is last option and I will avoid it if possible. My Windows Firewall is disabled, but it says that it is controlled by my system administrator – Jamgreen Aug 29 '14 at 12:08
  • 2
    You may get a `Invalid HTTP_HOST header` error when trying to connect to it, you should add it to the Allowed Hosts as [this](http://stackoverflow.com/questions/40582423/invalid-http-host-header) question explains. – DarkCygnus Apr 25 '17 at 15:56
  • Is it possible to open the same using some hostname on my local environment? –  Aug 04 '21 at 18:25
11

Just add your own IP Address to ALLOWED_HOSTS

ALLOWED_HOSTS = ['192.168.1.50', '127.0.0.1', 'localhost']

and run your server python manage.py runserver 192.168.1.50:8000

and access your own server to other computer in your network

YoKe
  • 115
  • 1
  • 4
  • 5
    Error: That IP address can't be assigned to. – Karam Qusai Dec 13 '19 at 08:18
  • Maybe you are adding ipaddress from other computer you need to add ipadress from your local machine – YoKe Aug 17 '20 at 06:06
  • 1
    or use this little script to define ip address in your code `def get_ipaddress():` `import socket` `host_name = socket.gethostname()` `ip_address = socket.gethostbyname(host_name)` `return ip_address` and after that you can declare this in your `ALLOWED_HOSTS = [get_ipaddress()]` – YoKe Mar 09 '21 at 05:09
7

Run the application with IP address then access it in other machines.

python manage.py runserver 192.168.56.22:1234

Both machines should be in same network, then only this will work.

sreekanth kuriyala
  • 1,197
  • 11
  • 11
5

This can be done in just 4 steps:

  1. Make sure in settings.py: ALLOWED_HOSTS = ['*']
  2. Run the server using: python manage.py runserver 0.0.0.0:3000
  3. Go to Windows security -> Firewall & network protection and turn off the windows firewall completely.

Now at this point, your Django API can be accessed within your local network using the URL: http:// Your-LAN-IP-address:3000/

  1. Now we have to open port 3000. Go to http://192.168.1.1 and login into your router. Now go to Advanced tab -> NAT -> Virtual server and fill the following fields alone:
  • WAN port - 3000
  • LAN port - 3000
  • LAN IP address - check your machine

Now at this point, your Django API can be accessed from anywhere using the URL: http:// Your-Public-IP-address:3000/

Nagulan S
  • 617
  • 5
  • 11
5

This is very very simple

python manage.py runserver 0.0.0.0:8000

change in setting.py

ALLOWED_HOSTS = ['*']

open linux terminal

sudo ifconfig

Get inet ipv4 address Run on other same local network PC

0

Check Your Computer's Ip Address
These commands will tell you all network info

ip add

or

ifconfig -a

If as you say it only gives you 127.0.0.1 then there are two options:

  1. Your network card is not attached or not recognized by the system

  2. Your network DHCP server is not runnning or not connected

after that add your ip address to your project's setting.py file
in my case my ip is 192.168.1.24

ALLOWED_HOSTS = ['192.168.1.24', '127.0.0.1', 'localhost']

then run your project using

python manage.py runserver 192.168.1.24:8000

now you can access your project to other devices :)

0

very simple, first you need to add ip to allowed host, ALLOWED_HOST =['*'] 2. then execute python manage.py runserver 0.0.0.0:8000 now you can access the local project on different system in the same network