app running on django dev server inaccessible from network computer - django

How do I access an app running on django dev server(ubuntu 15.10) from another machine on the same network(eg. a windows 7) ?
I am able to ping this machine from another network computer.
"python manage.py runserver 0.0.0.0:8000" - does not allow me to access the app from another network computer.
app uses django 1.5.9

https://docs.djangoproject.com/en/1.8/ref/django-admin/#django-admin-runserver
Note that the default IP address, 127.0.0.1, is not accessible from
other machines on your network. To make your development server
viewable to other machines on the network, use its own IP address
(e.g. 192.168.2.1) or 0.0.0.0 or :: (with IPv6 enabled).
runserver 0.0.0.0:8000
Make sure you open port 8000

python manage.py runserver 0.0.0.0:8000
is ok but you have to also modify settings.py of your app. You need to change ALLOWED_HOSTS.
For example put * to allow access for everybody or put only certain IPs to limit access:
ALLOWED_HOSTS = ['*']
more answers here:
CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False

Related

some advices on deploying Django app to product locally

I want to deploy (production not testing) Django app with PostgreSQL database for my company, however, for security reason I want the app to be on local network and not accessible through the internet. I need some recommendations and advices to achieve that on setup and tools.
Suppose I know python3 manage.py runserver 0.0.0.0:8000
EDIT: I wanted to be accessible by different machine on the same network.
You can just use command:
python3 manage.py runserver 8080
The default bind ip is 127.0.0.1, it can be only be access from your local network but not from the internet.
By default when you will runserver it will run on 127.0.0.1. And that will only be visible to your computer only
You have to do about two changes
First of all get your ip address of your local lan network by ipconfig command(in ubuntu). you can search other command to detect ip of your local lan network on your own
Let say your network ip is 192.168.0.100
Now go to settings.py
change ALLOWED_HOSTS=[] to
ALLOWED_HOSTS = ['192.168.0.100']
Now run
python3 manage.py runserver 0.0.0.0:8000
It will visible to all your clients connected on that network
They just have to type this url
192.168.0.100:8000
to see the website

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.

How to host a django website in my pc and view it in another pc?

I have a django project in my pc.
In terminal I've run python3 manage.py runserver <my ipaddress>:8001
When I try to open the link in another pc, it is showing error page which says:
Invalid HTTP_HOST header: '<my ipaddress>:8001'. You may need to add '<my ipaddress>' to ALLOWED_HOSTS.
What should I do?
And moreover is it possible to put some text in place of ipaddress in the url?
For example, I want to host it as myproject/ instead of that complex url.
On one condition this will work
if both computers are on the same network like local Hotspot or same
LAN network
steps:
add '*' in your django projects's setting file in Allowed Host it will look like
ALLOWED_HOSTS = ['*']
run your server on this ip 0.0.0.0 and port any like 8000 using this command
manage.py runserver 0.0.0.0:8000
run ifconfig if you are using linux ipconfig if windows then you will get your ip address of your server
Open browser in another computer and enter the ip of server shown in 3rd step with port as 8000
http://ip-of-server:8000
Instead of passing <my-ip-address> to the runserver command, pass 0.0.0.0.
If both the machines are in the same network you can run the application on 0.0.0.0 IP address (refers to all IPv4 addresses on the local machine). Refer this link wiki 0.0.0.0 for more details. So, on application server run this:
manage.py runserver 0.0.0.0:8001
Now, from the other machines, access it using http://youripaddresss:8001 , where < youripaddress > is the actual ip address of your machine.
If both computers are not on the same network (local hotspot or LAN network)
You can use ngrok to view whatever is running on your localhost from any device
Using ngrok to view your django project from any device
follow the steps below:
Add '*' in your django projects's setting file in Allowed Hosts:
ALLOWED_HOSTS = ['*']
Download ngrok from the official website
Unzip the downloaded file and then go to the directory where the ngrok file is located via your terminal
Then type the command:
ngrok http 8000
or
./ngrok http 8000
Now you can open the url generated by ngrok on any device to view what is running on your pc:
https://randomly_generated_subdomain.ngrok.io
PS: this can also be used for any webserver running locally, not just django site
ngrok is a great tool that can be used to:
Run personal cloud services from your home
Demo websites without deploying
Build webhook consumers on your dev machine
Test mobile apps connected to your locally running backend
Stable addresses for your connected devices that are deployed in the field
Run your server with this command python manage.py runserver 0.0.0.0:8000
Then you can access your website from any system connected to your wifi with an URL like 192.168.0.1:8000
You may get your IP Address using this command in CMD ipconfig in windows and ifconfig in mac
Also add your IP to ALLOWED_HOSTS in setting.py
ALLOWED_HOST = ['*'] in your settings.py
python manage.py runserver 0.0.0.0:8000
then make sure your machine firewall allows incoming and outgoing traffic.
I use linux machine so from control center go to firewall and allow both incoming and outgoing.
then on your local network machine.
:8000
This is it !
worked for me

Allowing external access through firewall to Django in Windows

I want to allow external access to my website, which is being hosted by Django (development server) on Windows 7. To run the server on port 8000, I enter:
python manage.py runserver 0.0.0.0:8000
If I disable the Windows firewall, then this can be accessed externally. However, enabling the firewall means that it cannot be accessed externally.
So, I tried adding an "Inbound Rule" at "Control Panel\System and Security\Windows Firewall\Advanced Settings". Here, I allowed inbound TCP access via port 8000.
However, my website still cannot be accessed externally. What else do I need to do?
Environment Version
OS:Windows 10
Python:3.9.13
Django:4.0.1
open cmd.exe,then run:
netsh advfirewall firewall add rule name="Django Web Server" protocol=TCP dir=in localport=8000 action=allow
If your public ip address is 1.1.1.1
settings.py
# load production server from .env
ALLOWED_HOSTS = ['localhost', 'localhost:5085', env('SERVER', default='127.0.0.1'),'1.1.1.1']
open cmd.exe,then run the server on port 8000:
python manage.py runserver 0.0.0.0:8000

Make Django development server a public website

I have a mac running Lion, and a D-link router DIR-601. I want to run my django development server as a public website for testing. I set up port forwarding to my computers local ip address, through port 8000. Then i entered the ip address of my router (obtained by typing my ip address in a browser) followed by :8000. Nothing. Can any one assist or point me to a tutorial for accomplishing this?
Try:
python manage.py runserver 0.0.0.0:8000
Because runserver will bind to address 127.0.0.1 by default, which is not accessible by other computers.
And don't forget to change settings.py. You have to configure also ALLOWED_HOSTS. For example:
ALLOWED_HOSTS = ['*']