-1

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.

  • Where is the code? Can you share full traceback? Please check similar question on SO [here](https://stackoverflow.com/a/61922664/8353711) – shaik moeed Jun 10 '22 at 17:15
  • https://cdn.cs50.net/web/2020/spring/projects/2/commerce.zip This is the distribution code given for this problem. should I add it to my question? – Pragati Chauhan Jun 10 '22 at 17:18
  • what does it mean by where the connection is occurring? I am still learning django so I don't understand it completely yet. but according to the lecture runserver should work with the given code but it is not working – Pragati Chauhan Jun 10 '22 at 17:24
  • ignore what I said about connections - this project uses a sqlite database so this has nothing to do with the DB backend connection. – topsail Jun 10 '22 at 17:31
  • Try to run `python manage.py runserver 0.0.0.0:8080` on port 8080. – shaik moeed Jun 10 '22 at 18:36
  • I tried running ```python manage.py runserver 0.0.0.0:8080``` and clicked the web server option in cs50 ide and it worked. Thank you – Pragati Chauhan Jun 11 '22 at 04:16
  • @PragatiChauhan It means, 8000 port is getting used by some other service. – shaik moeed Jun 11 '22 at 12:06

2 Answers2

0

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

Drew
  • 1
  • 1
0

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

Brian Thorpe
  • 317
  • 2
  • 13
  • the server is already running on this server – Pragati Chauhan Jun 10 '22 at 17:28
  • can you suggest what else information I should include in my question? – Pragati Chauhan Jun 10 '22 at 17:28
  • You can start django with a different port if need be - if some other program is using port 8000 – topsail Jun 10 '22 at 17:30
  • If you think the IDE is the problem just run the command outside of the IDE – Brian Thorpe Jun 10 '22 at 17:42
  • Okay so it seems that you are using an online IDE (https://ide.cs50.io/) instead of a local IDE. Which is not helping the problem. Are you not able to install python and IDE like VScode or Pycharm locally on your computer? It's pretty much impossible for anyone to help you since we can't use your schools IDE. The other alternative that might works that you can try your IDE's URL followed by :8000. You'll want to make sure the allowed hosts is [*] – Brian Thorpe Jun 10 '22 at 18:17