I have been setting up a Django website using the development server, and it works fine if I access it using the following address in my browser:
localhost:8000
I now want to be able to access the website from another computer (on the same network). I still want to use the development server for now. If my computer's name on the network is myname, and the domain is mydomain.com, then how can I enable this? If I just type in:
myname.mydomain.com:8000
I get a Server not found error.
Thanks.
It's not possible to access your computer like they way you explained in a LAN. There are couple of ways you can let other computers use your dev server directly.
First, run your Django app like this -
$ ./manage.py runserver 0.0.0.0:8000
So that the server listens to all the network interfaces for anyone accessing your IP, not just localhost. Then -
Find out your IP in the network. In the other computer in the same network open the hosts file(In linux, it's at /etc/hosts) and enter a new line -
enter.your.ip.here intended.domainname.com
Then you can access your dev server from that computer by entering intended.domainname.com:8000 or enter.your.ip.here:8000 in the browser. Cons: You have to alter the hosts file in each of the computer you intend to use the domain name instead of IP from and they all have to be in the same network.
You could use localtunnel. Then you can just execute -
$ localtunnel 8000
And it'll give you an url like http://xyz.localtunnel.com which you can share to anybody using the Internet and they'll be able to use your dev server.
Related
Suppose I am creating a todo list app in Flutter. I have used Django to connect flutter's backend with the local host database. Now my API's(Django Rest Framework) are working fine if the is on local machine. But what if I deploy my Flutter app to Play Store? Then I need to host my Django site as well or it can be upon the local machine?
Development
If you are in development the local machine is enough. For connecting the Flutter app to the Django development server follow the steps below.
connect your local server and mobile device to the same network (for example, a common wi-fi)
Get the IP address of the local machine. In Linux, the command is ifconfig,
and in Windows, it is ipconfig. It will be something like 192.168.1.8
Run the Django server with the following command in the terminal, providing your IP address you got in step 2:
python manage.py runserver 192.168.1.8:8000
To test, try access the IP address (with port) via. a browser on the phone. If it loads, the connection is correctly set up
Now you can use this address in your request in the HTTP request in Flutter
Production
If you are deploying the app in production, you can host a server (AWS/EC2, for example). You will get the IP address somewhere in the console. Deploy the code to the server and run the code there. Replace the local IP address in app with the IP address of the server. You can also use packages like Environ for this.
I want to debug a flask app on mobiles.
My application configuration allows to expose the app to the network:
application.run(host= '0.0.0.0',port=5000,threaded=True)
However, if I load mylocalIP:5000, it redirects to www.example.com, where the production site is hosted, and cannot figure out where it is written to resolve the redirect.
So I cannot see my local environment but in my local machine, and cannot debug the app on other machines - like mobile phones.
Where should I look to solve the problem ?
I must have changed configuration on my machine somewhere, I don't think it is related to flask.
Note: as alternative , I tried use my local host alias:
I'm using a mac, System Preferences > Sharing > Internet Sharing is enabled, other computers in local networks can access my local env at myLocal.local host, but still access to myLocal.local:5000 is forbidden for other machines but my computer.
You can do one thing, install Fiddler app and configure the reverse proxy on your mobile phone. This tutorial will help you to configure fiddler in android applications.
After configuring the reverse proxy, run the flask application on localhost or machine IP and you can access your machine IP on your mobile. Fiddler would also help you to intercept all the calls made to your application. If you don't want to inspect via fiddler you can directly put your mobile on same network of application.
Note: The ip addresses given are not the exact addresses. They are just for examples
I have a website built on flask running on a linux server that is using the internal ip address and a specific port... 192.168.10.10:1001. I know that the works on other computers on the same wifi.
How can I make the ip address public so that I can access the website without the wifi (outside network)? I know my the external ip address of the server... 100.250.250.25.
I have set up port forwarding so that I can 'access' my server from outside the network... 192.168.10.10:1000. I have accessed the server using the port forwarding but again it was on the same network. (Extra Question) Is that enough to access my server outside the network (or even using 100.250.250.25:1000)?
This applies to django as well because I have websites with django that I would like to use my server as well in the future. (Hopefully 192.168.10.10:1002).
You need to deploy your apps in live server like VPS. For the demonstration, you can try Heroku, pythonanywhere. You will find these tutorials available on other sites.
I am trying to access my site from my phone. Both my laptop and phone connected to the same wifi network. I tried to access the website with Postman and got a successful response. However when I try to access the site from my phone I get ERR_CONNECTION_REFUSED. What can be the reason for this?
I use this test url that I know works:
http://127.0.0.1:8000/policies/myModels_asJson
127.0.0.1 is the localhost so unless you're running your django app (or at least a webserver) on your phone that's the expected result.
If you want to test from your phone, you must
make sure the django server on your laptop (I assume it's running on the laptop) listens on the laptop's own ip (which should be a local ip in the 192.168.* range) - the simplest here is to run it on 0.0.0.0 (which means "listen on all ips"): ./manage.py runserver 0.0.0.0:8000
point your phone's browser to your laptop's local ip
I followed this tutorial to test going live with a django website.
I don't have a DigitalOcean droplet but a local machine I have that eventually could be used as a server. Therefore, in the steps where I had to put the domain name I used the local machine IP address (it's the same IP address I use to login with ssh).
All steps were ok and I have a response from whitin the local machine, i.e., if I open a browser in the local machine and with the IP address, the Django app runs ok.
However, the same does not happen if I open it from an external computer. I'm not sure if it was suppose to work like that. Is it? If not what extra steps do I need to do to go public?