简体   繁体   English

如何使网站与Django开发服务器兼容?

[英]How to make a website work with Django development server?

I understand that this is never to be done. 我知道这永远不会做。 But I have a situation where I need to get something done real quick. 但是我有一种情况,我需要尽快完成一些工作。 I have to do a website where may be 200 people would register for an event. 我必须做一个网站,可能有200人注册一个活动。 I need to present a simple registration form. 我需要出示一份简单的注册表。 Very basic functionality, register and view list of registrants. 非常基本的功能,注册和查看注册者列表。 Very few hits. 很少点击。 It would be live for about a month or so. 它将持续大约一个月的时间。

I know a little bit of Django which can allow me to put together this thing quickly. 我了解一点Django,可以让我快速整理一下。 However, I have only worked with the Django development server. 但是,我只使用Django开发服务器。

My problem is setting up Apache to work with Django. 我的问题是将Apache设置为可与Django一起使用。 I understand that, for Django, I need mod_wsgi installed. 我了解,对于Django,我需要安装mod_wsgi。 I have a VPS but mod_wsgi is not installed. 我有一个VPS,但未安装mod_wsgi。 I have asked my hosting provider to install it for me. 我已经要求托管服务提供商为我安装它。 Even if I can get mod_wsgi installed, it appears that it may take me some time to configure it and it may take a while. 即使我可以安装mod_wsgi,似乎也可能需要一些时间来配置它,并且可能要花一些时间。

I have the following questions. 我有以下问题。

  1. Can I run this website on the Django development server? 我可以在Django开发服务器上运行此网站吗? Will it hold up for very light traffic? 它会阻止交通流量吗?
  2. If I do, how do I get traffic to go from port 80 to the development server port. 如果这样做,我如何获得从端口80到开发服务器端口的流量。 From the landing page, I can have the port number added to all the subsequent URLs. 从登录页面,我可以将端口号添加到所有后续URL中。

I would also appreciate some guidance on getting Django to work with mod_wsgi. 我也希望获得有关使Django与mod_wsgi一起使用的一些指导。

Thanks 谢谢

I use cloud9 for development. 我将cloud9用于开发。 It is essentially a cloud ubuntu 14 virtual box, so it gives you a real url when django server is running (on port 80). 它本质上是一个云ubuntu 14虚拟盒子,因此当django服务器运行时(在端口80上),它为您提供了真实的URL。 Another use case of cloud 9 is for university classes, which is similar to your event use case. 云9的另一个用例是用于大学课程,这类似于您的事件用例。 You can go there and setup your django project for free and people can find the page normally. 您可以去那里免费设置django项目,人们可以正常找到该页面。 But there are some restarts in your workspace that prevents it to be real server. 但是您的工作区中有一些重新启动,使其无法成为真正的服务器。 If you pay 20 bucks per month they give you 2 premium workspaces that they assure that this does not happen ever. 如果您每月支付20美元,他们将为您提供2个高级工作区,以确保这种情况永远不会发生。 But I'm not sure if this is a good idea. 但是我不确定这是否是个好主意。 I could not even imagine what kind of errors would you get if all 200 people chose to login at the same time, for example. 例如,我什至无法想象如果所有200个人选择同时登录,会遇到什么样的错误。

Another way to go is making a free amazon AWS account (or digital ocean) and doing your deploy there. 另一种方法是注册一个免费的Amazon AWS账户(或数字海洋)并在那里进行部署。 AWS have 1 year free trial if you run only one microinstance with a particular setup which is plenty of time for your use case. 如果您仅使用一个特定设置运行一个微实例,AWS将有1年免费试用期,这对于您的用例来说是足够的时间。 I open the instance on AWS and SSH into it with cloud 9, so it feels like developing even in production. 我在AWS和SSH上使用云9打开了实例,因此即使在生产中也感觉像在开发。 I'm far from a devops expert but I could deploy Nginx, gunicorn, django in AWS following this tutorial. 我距离devops专家还很远,但是可以按照教程在AWS中部署Nginx,gunicorn,django。 You can do it too for sure, but is a lot of work. 您也可以肯定地做,但是要做很多工作。

Left my prefered choice for your use case to the end: pythonanywhere . 最后,我将您首选的选择留给您: pythonanywhere It has free trial and it's really easy to setup. 它具有免费试用版,并且设置起来非常容易。 You follow some very basic steps (doing stuff with mod_wsgi that I still dont understand) and make it work in minutes. 您遵循一些非常基本的步骤(使用我仍然不理解的mod_wsgi进行处理),并使其在数分钟内生效。 It's a whole business dedicated to serve python programs. 这是一个致力于提供python程序的整个业务。

Hope this helps 希望这可以帮助

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

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