Access VM Django Dev Server from Hyper-V VM Host Physical Machine - django

I am currently using Hyper-V to create a ubuntu 18.04.1 Desktop VM. On this VM I am creating a Django Dev Server using the following:
python manage.py runserver 0.0.0.0:8000
When I go to the 0.0.0.0:8000 on the vm I am presented with the Django debug page. However, when I to the url on my desktop I Unable to connect screen.
When I run the server with an IP of anything other than 0.0.0.0 or 127.0.0.1, I just Error: That IP address cab't be assigned to.
My Hyper-V Virtual Switch is an external network with my physical machines network adapter.
I am using Python 3.6.5, and Django 2.1
How do I access the Django Development Server on my VM hosts machine browser.

Related

Can't access django development server on a remote vps

I've just got a VPS with Ubuntu 18.04 on it.
Now I want to move my Django app I've been developing on a local PC to the VPS. I moved it and it starts okay - it says the server is running on 0.0.0.0:8000.
So the server is running fine, but I can't connect to it from a web browser on my local PC. Note: I'm trying to access it with ip of the server (ip:8000)
I have port 8000 enabled with netstat and I have added the IP to ALLOWED_HOSTS.
Update: I managed to access it using ngrok. By running the command ngrok http 8000 I got the url with which I was able to access the server.
Now I'd like to know how can I access it with IP.

How to access django development server on VM virtual box from actual computer?

Virtual box settingimageI have my actual laptop which has virtual box installed. I am running Ubuntu 18.04 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
I added ip address of host computer on allowed hosts on settings.py file but still its now working. If I did manage.py runserver 192.0.2.15:8000 on vm where 192.0.2.15 is ip address of vm, it gives error that ip address can't be assigned to.
Any idea how to fix it?

How to access Django runserver on a hostname rather than an IP address

My setup - Ubuntu 14.04 running on VirtualBox 4.3.24 client hosted on Windows 7.
I'd like to access my Django 1.7 dev server from another local PC, referenced by hostname rather than IP address - as the IP address could change.
./manage.py runserver 0.0.0.0:8000 works fine. The client PC browser can see my app on 192.168.2.xx:8000 But if I reboot the VirtualBox xx could become yy.
Is it possible to start runserver with a hostname?
Ideally I'd like to access the Django app with something like http://djangodev:8000 in the client browser. (I tried ./manage.py runserver djangodev:8000 - but 'Name or service not known')
Should I be looking to setup VirtualBox with a static IP instead of looking to configure runserver?
Many Thanks.
With a fixed ip address on your VM and I guess for your needs you just want the VM to be available by that name for your development machine, you can edit your /etc/hosts file to give it a ip-to-host name mapping. I'm assuming you are on a unix machine.
Add a line like this:
192.168.2.123 djangodev

I want to access my Django project which i am running from Red Hat machine

The Development server gets started on he System's IP.
[Yash#Yash qpcm]$ python manage.py runserver 192.168.1.57:8000
Validating models...
0 errors found
Django version 1.4, using settings 'qpcm.settings'
Development server is running at http://192.168.1.57:8000/
Quit the server with CONTROL-C.
I can access this ip address from the same system, but this ip is inaccessible from the other systems connected through same wifi and Lan. The other systems are ubuntu and Windows.
192.168.1.57 is a private IP. Instead, you need to bind the server to an external IP with something like python manage.py runserver 0.0.0.0:8000.

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 (e.g. 192.168.x.x) 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