简体   繁体   English

何时以及为何使用Django开发服务器?

[英]When and why to use Django development server?

I understand that it's simple and doesn't require any installation whatsoever, but are there any other reasons to use it for long-term development instead of Apache with mod_wsgi? 我知道它很简单,不需要任何安装,但有没有其他理由使用它进行长期开发而不是使用mod_wsgi的Apache? As a Django newbie, I just find deployment from development to live (Apache) environment quite cumbersome and annoying, so the question that comes into my mind is: Isn't it simpler to just use mod_wsgi on localhost too? 作为一个Django新手,我发现从开发到实时(Apache)环境的部署非常麻烦和烦人,所以我想到的问题是:在localhost上使用mod_wsgi是不是更简单? Only mention about this in Django manual I found was: 在我发现的Django手册中只提到了这一点:

We've included this with Django so you can develop things rapidly, without having to deal with configuring a production server -- such as Apache -- until you're ready for production. 我们已经将它包含在Django中,因此您可以快速开发,而无需处理配置生产服务器(如Apache),直到您准备好进行生产。

You sometimes need the production setup locally when you're developing. 在开发过程中,有时需要在本地进行生产设置。 I've needed it when I was messing with some subdomain related code that tied into the application and needed to mimic my real server locally. 当我弄乱一些与应用程序绑定并需要在本地模仿我的真实服务器的子域相关代码时,我需要它。

However, for most things, the dev server is a big win. 但是,对于大多数事情来说,开发服务器是一个巨大的胜利。 Here are a few points. 以下是几点。

  1. Like rebus mentioned, the auto restart. 就像提到的rebus一样,自动重启。
  2. Tracebacks on the console and useful debugging information. 控制台上的回溯和有用的调试信息。
  3. You can stick pdb.set_trace() into parts of your code and get a debugger prompt while a view method is executing if you want to look at stuff. 您可以将pdb.set_trace()粘贴到代码的某些部分,并在执行视图方法时获取调试器提示,如果您想查看内容。
  4. The entire stack runs as a single user (you) which you have complete control over. 整个堆栈作为您完全控制的单个用户(您)运行。
  5. One command to start and run. 一个启动和运行命令。

These come with a price which is reduced performance and inability to handle real life traffic. 这些都是降低性能和无法处理实际流量的价格。 That's why you need a real web server to run it in production. 这就是为什么你需要一个真正的 Web服务器来在生产中运行它。

When I create a simple Django app for local users to populate data into a DB i usually leave it running with the development server. 当我为本地用户创建一个简单的Django应用程序以将数据填充到数据库中时,我通常会让它与开发服务器一起运行。 I've never had any problems... If it's in a local server and not exposed to the internet it should be ok to use it. 我从来没有遇到过任何问题......如果它在本地服务器上并且没有暴露在互联网上,那么它应该可以使用它。

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

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