1

我在这里按照教程进行操作,到了我打电话的地方djrun,发现没有任何事情发生http://localhost:8000

4

1 回答 1

1

除了确保 Django 的 runserver 已正确绑定之外./manage.py runserver 0.0.0.0:8000,您还需要检查 Vagrant 是否正在为主机转发端口。这可以看作是来自vagrant up命令的 STDOUT 的一部分:

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'wagtail-base-v0.3'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: gilles_default_1431922616155_88032
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 8000 => 8111 (adapter 1) # <== This is the relevant line.
    default: 22 => 2222 (adapter 1)

因此,服务器位于http://localhost:8111/

编辑

根据下面的评论,您还可以通过 Vagrant 配置文件设置此值。配置键称为config.vm.forwarded_port. 下面是启动一个示例文件(由 Wagtail 默认提供):

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant::Config.run do |config|
    # Base box to build off, and download URL for when it doesn't exist on the user's system already
    config.vm.box = "wagtail-base-v0.3"
    config.vm.box_url = "http://downloads.torchbox.com/wagtail-base-v0.3.box"

    # Forward a port from the guest to the host, which allows for outside
    # computers to access the VM, whereas host only networking does not.
    config.vm.forward_port 8000, 8111 # <-- This is the relevant line.
于 2015-05-18T04:29:48.850 回答