manage.py runserver

PythonDjango

Python Problem Overview


I am running python manage.py runserver from a machine A when I am trying to check in machine B. The url I typed is http://A:8000/ .

I am getting an error like The system returned: (111) Connection refused

Python Solutions


Solution 1 - Python

You can run it for machines in your network by

> ./manage.py runserver 0.0.0.0:8000

And than you will be able to reach you server from any machine in your network. Just type on other machine in browser http://192.168.0.1:8000 where 192.168.0.1 is IP of you server... and it ready to go....

or in you case:

  1. On machine A in command line ./manage.py runserver 0.0.0.0:8000
  2. Than try in machine B in browser type http://A:8000
  3. Make a sip of beer.

Source from django docs

Solution 2 - Python

You need to tell manage.py the local ip address and the port to bind to. Something like python manage.py runserver 192.168.23.12:8000. Then use that same ip and port from the other machine. You can read more about it here in the documentation.

Solution 3 - Python

I was struggling with the same problem and found one solution. I guess it can help you. when you run python manage.py runserver, it will take 127.0.0.1 as default ip address and 8000. 127.0.0.0 is the same as localhost which can be accessed locally. to access it from cross origin you need to run it on your system ip or 0.0.0.0. 0.0.0.0 can be accessed from any origin in the network. for port number, you need to set inbound and outbound policy of your system if you want to use your own port number not the default one.

To do this you need to run server with command python manage.py runserver 0.0.0.0:<your port> as mentioned above

or, set a default ip and port in your python environment. For this see my answer on https://stackoverflow.com/questions/23639085/django-change-default-runserver-port/38094213#38094213

Enjoy coding .....

Solution 4 - Python

Just in case any Windows users are having trouble, I thought I'd add my own experience. When running python manage.py runserver 0.0.0.0:8000, I could view urls using localhost:8000, but not my ip address 192.168.1.3:8000.

I ended up disabling ipv6 on my wireless adapter, and running ipconfig /renew. After this everything worked as expected.

Solution 5 - Python

in flask using flask.ext.script, you can do it like this:

python manage.py runserver -h 127.0.0.1 -p 8000

Solution 6 - Python

For people who are using CentOS7, In order to allow access to port 8000, you need to modify firewall rules in a new SSH connection:

sudo firewall-cmd --zone=public --permanent --add-port=8000/tcp
sudo firewall-cmd --reload

Solution 7 - Python

First, change your directory:

cd your_project name

Then run:

python manage.py runserver

Solution 8 - Python

I had the same problem and here was my way to solve it:

First, You must know your IP address. On my Windows PC, in the cmd windows i run ipconfig and select my IP V4 address. In my case 192.168.0.13

Second as mention above: runserver 192.168.0.13:8000

It worked for me. The error i did to get the message was the use of the gateway address not my PC address.

Solution 9 - Python

Ok just came across this post this is a little off topic but hopefully explains a few things, The IP 127.0.0.1 points to your network card so any traffic that you cause to go to that IP address will not leave your computer.

For example modern network cards in laptops for example will not even give you that IP if you are not connected to a wifi or cabled network so you'll need to be connected at least to activate the card.

If you need to run multiple servers on the same machine but want to access them with a domain then you have a couple of options

  1. edit your computers host file to define the domain and what IP it goes to
  2. use a DNS Alias I set up using a cname record years ago *.local.irishado.com will point to 127.0.0.1

so for example these three domains will point to your local machine

will all point to your local machine then in python projects you will need to edit the projects setting file ALLOWED_HOSTS property to hold the domain it will accept

ALLOWED_HOSTS = ['site1.local.irishado.com']

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsreekanthView Question on Stackoverflow
Solution 1 - PythonPolView Answer on Stackoverflow
Solution 2 - PythonJason WebbView Answer on Stackoverflow
Solution 3 - PythonAmrendraView Answer on Stackoverflow
Solution 4 - Pythonbenrules2View Answer on Stackoverflow
Solution 5 - PythonwuxueqianView Answer on Stackoverflow
Solution 6 - PythonErnieView Answer on Stackoverflow
Solution 7 - Python VaibhavView Answer on Stackoverflow
Solution 8 - Pythonalvaro562003View Answer on Stackoverflow
Solution 9 - PythonIrishAdoView Answer on Stackoverflow