Django Cannot Be Accessed From Localhost
Solution 1
I cannot access localhost:8000 from my browser if I run python manage.py runserver
I don't know why that command cannot work in my laptop, but in my pc it just works.
====
ok, so my solution now is to use ipv6 and port 8000 which is
python manage.py runserver [::]:8000
Solution 2
Just try http://0.0.0.0:8000
instead of localhost:8000
Default localhost
value is http://127.0.0.1
If you see the runerver result you have :
starting developement server at http://0.0.0.0:8000
Because you told that django server start at http://0.0.0.0:8000
when you run this command :
python manage.py runserver 0.0.0.0:8000
Solution 3
I'm also beginner to django, but I needed following things in order to run the server:
- In
settings.py
, addedALLOWED_HOSTS
as
ALLOWED_HOSTS = [ 'elearning.com' ]
where elearning.com is my hostname. You can have multiple hosts separated with comma. - Used following command to run the server:
python manage.py runserver [::]:8000
or
python manage.py runserver 0.0.0.0:8000
or
python manage.py runserver 0:8000
.
It will now listen to all interfaces. Read Django doc here. - Browsed to given hostname. In my case, it is http://elearning.com:8000/
I tried writing IP in ALLOWED_HOSTS
but it didn't work, I could not open http://192.168.x.x:8000 in browser. Can anyone please correct me?
Richard Octovianus
Updated on June 04, 2022Comments
-
Richard Octovianus almost 2 years
It's kinda weird I cannot access django from localhost but I able to access it from local IP.
python manage.py runserver 0.0.0.0:8000
then when I try to access from
My host file
127.0.0.1 lmlicenses.wip4.adobe.com 127.0.0.1 lm.licenses.adobe.com 127.0.0.1 gc.kis.scr.kaspersky-labs.com ff.kis.scr.kaspersky-labs.com ie.kis.scr.kaspersky-labs.com 0.0.0.0 gc.kis.scr.kaspersky-labs.com ff.kis.scr.kaspersky-labs.com ie.kis.scr.kaspersky-labs.com
I'm guessing something wrong with windows firewall or kaspersky,but I don't know what to do.
I've add exception to port 8000 and python.exe too
-
Richard Octovianus over 8 yearsIt's the same. I still cannot access even with 127.0.0.1:8000 nor 0.0.0.0:8000
-
Arash Hatami over 8 yearswhy yo want to change IP address of django server ? just run the normal command
python manage.py runserver
@RichardOctovianus -
Vaibhav Jain over 8 years
Use runserver 0.0.0.0:8000 to make it listen on all interfaces
from Django official documentation code.djangoproject.com/ticket/396 -
Richard Octovianus over 8 yearseven with just "python manage.py runserver" i cannot access through localhost:8000 in my browser. that's why i use 0.0.0.0:8000 to be able accessed from my lan ip
-
Richard Octovianus over 8 yearsseems nothing to do with hosts file, I tried it before
-
Vaibhav Jain over 8 yearsWell in my Case it did.