Can't access django development server on a remote vps - django

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.

Related

Getting Not Found: / while trying to access Django server from other device in LAN

I am trying to access Django server from outside the device but within LAN. I have exposed my port 8000 for same and then ran -
python manage.py runserver 172.30.xxx.xxx:8000
Now, while trying to connect from other device using link http://172.30.xxx.xxx:8000 , I end up getting "The connection was reset" in browser. In the Django console it shows "Not Found: /".
But if I try to access the same link from the device where server is running I am able to access.
What might be the possible glitch here?
To make your development server viewable to other machines on the network on LAN, this procedure works for me
Run the server like this python manage.py runserver 0.0.0.0:8001
Access the server 192.168.1.xxx:8001(this IP will be different for you) from another station on the LAN
So, it turns out there was a problem with gateways in LAN. Accessing from same gateway lets me access the site.

Accessing django website hosted on vm with mobile device

I run my django website with python manage.py runserver 0.0.0.0:8080 on Vagrant which is set up to forward 8080 port to 8081 on host machine. I'm able to access this website on host by going to it's local ip (192.168.X.X) but can't on mobile device (of course also by going into it's local ip).
Any idea? All I could find about this is to run server with 0.0.0.0 what is already happening in my case.
Never mind, I've forgot to enable public_network in my Vagrantfile.

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

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.

Access web server on VirtualBox/Vagrant machine from host browser?

I have a Django web server on a VirtualBox/Vagrant machine running Ubuntu.
I have followed this guide to create a Django project: https://docs.djangoproject.com/en/dev/intro/tutorial01/
I have a web server running at http://127.0.0.1:8000/ inside my guest machine. This is the first time I am running a Django web server. It is supposed to be a hello world app.
How can I access this web application from my host browser?
I have tried running ifconfig in the guest to get the IP that I should visit I found a promising IP address in inet addr.
But I have tried entering the following into my host browser and it didn't work.
http://inetaddrnumbers:8000/
How can I access the web server from my browser?
Try this.
Open the vagrant file (should be in the directory where you specified to create a new vagrant machine).
Search for config.vm.network. If you didn't setup the file earlier, it should be commented.
Change it to look something like this config.vm.network "private_network", ip: "55.55.55.5". Here ip address (55.55.55.5) can be any ip address you want.
Now logout from the vagrant machine and reload your vagrant machine by this command vagrant reload.
Again ssh to your vagrant machine and restart your django server by this command python manage.py runserver 0.0.0.0:80. Again the port address (80) can be 8000 if you want so.
After that, in your browser, enter the following address 55.55.55.5, and hopefully you should see your webapp.
Now if you would like to go further, you can edit your host file, and add this line
55.55.55.5 mynewdomain.com
Then in your browser, enter the follow address,
mynewdomain.com
And you should see your web app. Note that, www is not added in the domain name inside the host file, so only mynewdomain.com can be accessed. You can however add it.
Hope this helps. Cheers.
Complementing #Kakar answer, this configuration can also be done using this:
config.vm.network "private_network", type: "dhcp"
This will assign an IP automatically.
For further reading: https://www.vagrantup.com/docs/networking/private_network.html

Installed "Python-django" on my Virtualbox but not able to access the web pages from host machine web browser

I am pretty new to Web-Development
I have Python-Django and apache2 installed on VirtualBox.The VirtualBox adapter settings are OK since i am able to visit the web pages hoisted from apache2.
Now the problem is when i tried to visit the pages hoisted by django inbuilt web-server
It didn't opened.
For apache2 port number is 80 and for django port number is 8000
Please help me to get through this problem
Django development web server normally binds to localhost (127.0.0.1) only, therefore you can only access it from the same machine (or VM). You can change this behavior by starting it using:
python manage.py runserver 0.0.0.0:8000
This way it will bind to every IP address (both 127.0.0.1 and whatever IP address you gave to your VM) so that you can access it from "outside".