简体   繁体   中英

how to access django development server on virtual machine from actual computer

Okay so I have my actual laptop which has vmware player installed. I am running lubuntu as a virtual machine and I installed django on the virtual machine and am testing my app so I did python manage.py runserver and I can access the app by visiting 127.0.0.1:8000 from my VM, however, If I go to 127.0.0.1:8000 from the actual computer (not the VM), it says 'chrome could not connect to 127.0.0.1:8000'.. Any idea how to fix it?

You can try running the server on 0.0.0.0

python manage.py runserver 0.0.0.0:8000

The IP address 0.0.0.0 means "all IP addresses on the local machine" (or all IPv4 addresses on the local machine).

Next, you will need the ip address of your VM. Visting http://<ip_address_of_vm>:8000 on other computers should access the django development server on your VM.

Note: If your VM only has an internal IP (eg 192.168.xx) then only computers on the same network can visit the VM.

I was able to get @Kerberos answer to work. (not enough points to comment so I'm adding it as a seperate answer).

I am running Ubuntu 12.04 LTS in a guest OS in VMWare. The host laptop is running Windows 8.

As mentioned by Kerberos, in VMWare, go to Player ==> Manage ==> Virtual Machine Settings...

On the Hardware tab, select Network Adaptor , then select the radio button for Bridged: Connect directly to the physical network . Select OK

In the VM, the network connection information should now have the same IP address of the host OS internet connection. In my case: 192.168.1.141 (yours will vary).

In the VM, start Django using python manage runserver 192.168.1.141:8000

Using this method, I am able to access the webserver running in the VM at this IP address from within the VM, from host machine, and from other systems on the same 192.168.1.xxx network.

to access virtual machine (guest) from outside the host computer, you have to set the guest network mode to bridge

Bridge-mode connects the guest to the actual network so that other machines can connect to it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM