Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

I am encountering an error message while trying to start the server using the command prompt:

python manage.py runserver 0.0.0.0:8000

The error message is:

C:\abc>python manage.py runserver 0.0.0.0:8000

Validating models...

0 errors found

Django version 1.4.9, using settings 'abc.settings'

Development server is running at http://0.0.0.0:8000/

Quit the server with CTRL-BREAK.

But I can't access in the browser via http://127.0.0.1:8000

It is showing :

Unable to connect

Firefox can't establish a connection to the server at 127.0.0.1:8000.

The site could be temporarily unavailable or too busy. Try again in a few moments.

If you are unable to load any pages, check your computer's network connection.

If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.

But when I am attempting the same by:

python manage.py runserver 

It is working fine. What can be the issue?

2 Answers

0 votes
by (107k points)

I think that the Port 8000 is currently used by your external IP. I would suggest you check if the process is running or not, if it is running then kill it.

You can check that by opening the ports with:

netstat -a 

In Debian you will get the PID with:

 netstat -tulpn | grep 8000

 The last line will show you something like 1234/python. Now kill it with:

 kill 1234

The other option will just restart your system.

0 votes
ago by (3.1k points)

Following steps can provide the resolution 

1. Verify Python and Django Installation 

Verify that you have installed Python and Django correctly. You can do this by running the following commands: 

python --version 

django-admin --version 

2. Activate Virtual Environment 

Make sure that the virtual environment you are using is activated; otherwise, activate it with the following command: 

# Using Windows 

.\\venv\\Scripts\\activate 

# Using macOS/Linux 

source venv/bin/activate 

3. Settings Error Check 

Check for any error in your settings.py file, especially that ALLOWED_HOSTS is correctly defined as follows: 

ALLOWED_HOSTS = ['localhost', '127.0.0.1'] 

4. Pending Migrations Check 

Run migrations so that the database is all up to date: 

python manage.py migrate 

5. Test Port Availability 

The development server by default runs on port 8000. Make sure it is not used. You can change the port: 

python manage.py runserver 8080 

6. Error Messages 

Run the command and look for error messages in the console. They may be a clue to what you are doing wrong. 

7. Firewalls 

If you have your server running on some remote machine, ensure your firewalls allow traffic on the selected port. 

8. Install All Missing Packages 

Sometimes, missing dependencies might break your server. Ensure all necessary packages are installed: 

pip install -r requirements.txt 

Related questions

0 votes
4 answers
asked Apr 11, 2021 in Python by laddulakshana (16.4k points)
0 votes
1 answer
asked Feb 25, 2021 in Python by laddulakshana (16.4k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...