0

I am trying to follow this online class, and I am stuck on the part where I access a local website made by django. The tutorial that I follow is this one by freecodecamp, and I get stuck by the 11min mark where I try to access the output site http://127.0.0.1:8000/ . I am following this tutorial on the browser version of Jupyter Notebook.

Tutorial: https://www.freecodecamp.org/news/create-an-e-commerce-site-with-django-and-vue/

The 'python manage.py runserver' line runs, and I get the following output:

System check identified no issues (0 silenced).
April 16, 2021 - 03:37:04
Django version 3.2, using settings 'djacket_django.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

When I copy and paste the server address into the browser, I just get the following error saying that I wasn't able to connect to the site:

 Unable to connect
 Firefox can’t establish a connection to the server at 127.0.0.1:8000.

The only resource I really found that addressed this issue was the following post, but when I went through my netstat list, there were no IPs listing :8000, so I don't think that I am using up that address already.

Post: Django manage.py runserver is not working

Albert Garcia
  • 23
  • 1
  • 8
  • Check your HOSTS file to see if there is an entry causing this. – Lars Apr 16 '21 at 03:59
  • @Progam I found a HOSTS file in "C:\Windows\System32\drivers\etc", opened the HOSTS file with notepad, and everything there was commented out. There were no entries in that file. – Albert Garcia Apr 16 '21 at 04:10
  • Verify that the server you are running is actually on the same machine as the browser. This is likely not the case if you are using WSL2. What OS are you using? – Mike Slinn Apr 16 '21 at 04:10
  • @MikeSlinn I am using Windows 10. How would I check that out? – Albert Garcia Apr 16 '21 at 04:11

1 Answers1

1

Sounds like you are using WSL2 and have not yet discovered that the WSL2 VM's IP address is not the same as the Windows IP address. Windows has its own idea of what localhost might be!

TL;DR: Use GWSL to run WSL2 apps on X Windows. This will allow you to run a browser from WSL2 over X Windows, and no worries.

Mike Slinn
  • 7,705
  • 5
  • 51
  • 85
  • Sounds good. I will try this out. I have never heard of WSL2 before, so this will definitely help. – Albert Garcia Apr 16 '21 at 04:17
  • Unless someone else set up your machine, you would know if it had WSL2. Takes work to set up, and out of the box it is not set up. – Mike Slinn Apr 16 '21 at 04:19
  • Could I have downloaded WSL2 accidentally while downloading all my python packages? I really have no idea what I've been doing. I finished downloading GWSL a little while ago, and I am trying to figure out how to use it now. – Albert Garcia Apr 16 '21 at 04:22
  • No way that happened by accident. WSL2 may be a step to far for you right now. It takes time to get WSL2 set up right. Don't complicate your life unnecessarily. One step at a time! – Mike Slinn Apr 16 '21 at 04:26
  • Haha okay. Yeah, so I guess this isn't my problem, then – Albert Garcia Apr 16 '21 at 04:28
  • Please describe in your question how you are running your program. Using an IDE? If so, which? Using Windows Terminal? Something else? How is your program launched? – Mike Slinn Apr 16 '21 at 04:29
  • I was trying to use my Spyder IDE at first, but I decided to give up on that and just go to the online Jupyter IDE since there would be no setup necessary for that. In the online Jupyter IDE, there are terminals and consoles, but those only apply to an online save space for the program that I made. – Albert Garcia Apr 16 '21 at 04:36
  • However you invoke a program or function, when you ask for help, please show how something is invoked, so others can understand or replicate your situation. Details often matter. – Mike Slinn Apr 16 '21 at 10:55