Access Django app from other computers

后端 未结 4 2010
臣服心动
臣服心动 2021-02-14 22:17

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

相关标签:
4条回答
  • 2021-02-14 22:58

    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.

    0 讨论(0)
  • 2021-02-14 23:03

    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/

    0 讨论(0)
  • 2021-02-14 23:05

    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

    0 讨论(0)
  • 2021-02-14 23:22

    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

    0 讨论(0)
提交回复
热议问题