Local Django website won't load in browser

后端 未结 4 1178
终归单人心
终归单人心 2021-01-15 06:16

I\'m guessing there\'s a very simple solution to this, but I searched every forum and setup guide and can\'t figure it out:

I built a Django/CentOS-6.3 environment

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-15 07:04

    the host's "127.0.0.1" is not the same as the guest's "127.0.0.1". Per default the command

    python manage.py runserver
    

    listens only to the guest's localhost. You should be able to test it from within the vm (use "vagrant ssh" to login) and run

    curl -I http://127.0.0.1:8000/
    

    The host as a different IP. To access the development server from the host you have to start it without ip restriction:

    python manage.py runserver 0.0.0.0:8000
    

    Yes:

    python manage.py runserver [::]:8000
    

    should be the same. But that's IPv6 syntax AFAIK. Are you sure that the "manage.py runserver" command supports IPv6 by default? I've never used ipv6 addresses w/ django, but looking at the source (https://github.com/django/django/blob/master/django/core/management/commands/runserver.py) there seams to be a flag that the default to False ("--ipv6"). Perhaps that's the "real" problem?

    Regards,

提交回复
热议问题