Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 289
SilentDev Avatar asked Aug 31 '13 18:08

SilentDev


2 Answers

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.

like image 177
ChrisFreeman Avatar answered Oct 12 '22 11:10

ChrisFreeman


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 (e.g. 192.168.x.x) then only computers on the same network can visit the VM.

like image 29
Derek Kwok Avatar answered Oct 12 '22 09:10

Derek Kwok