简体   繁体   English

django虚拟主机

[英]django virtual host

I'm new to django and am coming from the MAMP and PHP world. 我是django的新手,来自MAMP和PHP领域。 How do you setup virtual hosts in django for a site? 如何在Django中为站点设置虚拟主机? For example, when you run the server, instead of going to 127.0.0.1:8000, I'd like to go to mysite.dev locally? 例如,当您运行服务器时,我想本地访问mysite.dev,而不是转到127.0.0.1:8000? I keep reading about wsgi for Apache, but am unsure if this is the easiest way. 我一直在阅读有关Apache的wsgi的信息,但是不确定这是否是最简单的方法。

Basically, how do you setup virtual hosts for django? 基本上,您如何为Django设置虚拟主机? Any links or code is appreciated! 任何链接或代码表示赞赏!

Keep in mind that unlike PHP, you don't need Apache and virtual hosts to develop and test django applications as django comes with a built-in development server . 请记住, PHP 不同 ,由于django带有内置的开发服务器 ,因此您不需要Apache和虚拟主机来开发和测试django应用程序。

You would only need Apache when you are ready to deploy your application, and to set that up you should read how to deploy with wsgi . 仅在准备好部署应用程序时才需要Apache,并且要进行设置,您应该阅读如何使用wsgi进行部署

I'm not sure why you would want to do this in development. 我不确定为什么要在开发中这样做。 The dev server doesn't manage anything like that, it just listens to the port you tell it to and runs Django code in response. 开发服务器不会管理类似的事情,它只是侦听您告诉它的端口,并运行Django代码作为响应。 That means you can just hack your hosts file to tell it that mysite.dev maps to localhost. 这意味着您可以破解您的hosts文件,以告诉它mysite.dev映射到localhost。 You'd still need to access port 8000 though - unless you tell runserver to bind to port 80, for which you'll need to use sudo . 但是,您仍然需要访问端口8000-除非您告诉runserver绑定到端口80,否则您将需要使用sudo

Alternatively, as you say you can set up Apache with mod_wsgi as if it were a production server - but then you'll lose the automatic code reloading, and will have to restart Apache after every change to your Python code (although there are ways around this, see the mod_wsgi documentation). 另外,正如您所说,您可以将mod_wsgi设置为Apache,就好像它是生产服务器一样-但是您将失去自动重载代码的功能,并且在每次更改Python代码后都必须重新启动Apache(尽管有很多方法可以解决)请参阅mod_wsgi文档)。

Seems like a lot of bother for almost no gain. 似乎无济于事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM