I'm new to python and django. Yesterday I did the "python manage.py runserver" for the first time(just after django-admin startproject ..) and it showed starting development server at http://127.0.0.1:8000/. But in chrome it said "this site cant be reached".
After searching the error I realized I had to add '127.0.0.1' in the list of ALLOWED_HOST(which was an empty list at the beginning) in settings.py. This resolved the error and django congratulations page showed up.
But today again the same "this site cant be reached, 127.0.0.1 refused to connect" error.
Can someone help me out with this?
This link has the project tree
EDIT: I also had problem with installation of django itself. While doing "pip install django" there was an error like "pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available" and many other line of errors.
After reading comments in stack overflow someone suggested to do pip install from anaconda prompt and only after that I was able to install django.
Old but still without solution.
I had created
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
for remote testing and could not run it locally.
After setting
STATIC_ROOT = ''
local server is working and reachable at 127.0.0.1:8000
I had the same issue and I used the whole url which is http://127.0.0.1:8000/ and it worked
I ran into the same issue.
Tried using runserver like this - python manage.py runserver 5000
and I was able to reach the site at http://127.0.0.1:5000/
for dev purposes you can add:
['*']
to allowed hosts.
The problem here is surely related to your OS, maybe you have another app that interfere with the django server, eventually you can run
python manage.py runserver 0.0.0.0:8000
and try to access to access the project from http://your-IPv4 address:8000, do not forget also to change your settings allowed hosts to ['*'] to accept all address.
Try to add this view to your project folder and point it to the '/' path
views.py
from django.http import HttpResponse
def homepage(request):
return HttpResponse('hello world')
urls.py
from . import views
urlpatterns = [
path('/', views.homepage)
]
An new project doesn't need any extra settings in order to work with the development server (runserver
command) so maybe you have some process bloquing the localhost address, or maybe an extension or something in your browser.
As your problem is with an empty project maybe recreating it could solve it. I know this is not a "solution" but try when you're recreating the project again that you don't miss nothing. I wrote this article some weeks ago, I you're new with django it could be useful.
In my case with Python 3.7 in PyCharm, I solved the problem with upgrading Django version to 3.2.8. You may try this using the following path: File>Settings>Project Interpreter
i got he same problem recently, and got it to work by typing in the terminal: python manage.py runserver 0.0.0.0:8000