why is django server not working? (connection refused error)

3.1k Views Asked by At

I am doing a course : cs50 web programming with python and in project 2 Commerce while using python manage.py runserver I am getting this error:

This site can’t be reached 127.0.0.1 refused to connect.

this is project 2 commerce. https://cs50.harvard.edu/web/2020/projects/2/commerce/

I have not made any changes to the distribution code

for my last project I was able to make it work by using this code in settings.py :

ALLOWED_HOSTS = ["ide-2f9427eaa96d41debb489eacf31c97d6-8080.cs50.ws"] and changing url to the same but on using it in this project I get this error:

403 Forbidden

edit

this is the solution I found from the comments:

As suggested in the comments I changed ALLOWED_HOSTS = [*] in settings.py of my django file. then in the terminal I tried running the command python manage.py runserver 0.0.0.0:8080

On clicking the link I got a URL like this:

{ide URL}:8080

and this error:

This site can’t be reached

next I changed the URL manually to {IDE URL}-8080.cs50.wswhich is the URL for the web server in the IDE I am using. this seemed to work for me.

The problem may have been because port 8000 is being used by another service and earlier I was not able to use port 8080 because I was using the wrong URL for my IDE's web server.

2

There are 2 best solutions below

6
Drew On

check settings.py and make sure debug is set to True. Then go to allowed hosts and set it to ['*']. This will allow anyone on your system to connect to localhost server

5
Brian Thorpe On

By default the server runs on port 8000 so you might want to try 127.0.0.1:8000 in your URL