简体   繁体   English

将Django应用程序迁移到Google App Engine?

[英]Migrating Django Application to Google App Engine?

I'm developing a web application and considering Django, Google App Engine, and several other options. 我正在开发一个Web应用程序并考虑Django,Google App Engine和其他几个选项。 I wondered what kind of "penalty" I will incur if I develop a complete Django application assuming it runs on a dedicated server, and then later want to migrate it to Google App Engine. 我想知道如果我开发一个完整的Django应用程序(假设它在专用服务器上运行),然后想要将其迁移到Google App Engine,我会产生什么样的“惩罚”。

I have a basic understanding of Google's data store, so please assume I will choose a column based database for my "stand-alone" Django application rather than a relational database, so that the schema could remain mostly the same and will not be a major factor. 我对Google的数据存储有一个基本的了解,所以请假设我将为我的“独立”Django应用程序而不是关系数据库选择基于列的数据库,这样架构可以保持大部分相同而且不会是主要的因子。

Also, please assume my application does not maintain a huge amount of data, so that migration of tens of gigabytes is not required. 另外,请假设我的应用程序没有维护大量数据,因此不需要迁移数十GB。 I'm mainly interested in the effects on the code and software architecture. 我主要对代码和软件架构的影响感兴趣。

Thanks 谢谢

Most (all?) of Django is available in GAE, so your main task is to avoid basing your designs around a reliance on anything from Django or the Python standard libraries which is not available on GAE. 大多数(全部?)Django都可以在GAE中使用,所以你的主要任务是避免依赖于Django或GAE上没有的Python标准库。

You've identified the glaring difference, which is the database, so I'll assume you're on top of that. 你已经确定了明显的差异,即数据库,所以我假设你已经掌握了。 Another difference is the tie-in to Google Accounts and hence that if you want, you can do a fair amount of access control through the app.yaml file rather than in code. 另一个区别是与Google帐户的搭配,因此如果您愿意,可以通过app.yaml文件而不是代码执行相当数量的访问控制。 You don't have to use any of that, though, so if you don't envisage switching to Google Accounts when you switch to GAE, no problem. 但是,您不必使用其中任何一项,因此,如果您在切换到GAE时未设想切换到Google帐户,则没问题。

I think the differences in the standard libraries can mostly be deduced from the fact that GAE has no I/O and no C-accelerated libraries unless explicitly stated, and my experience so far is that things I've expected to be there, have been there. 我认为标准库中的差异大部分可以从GAE没有I / O和没有C加速库这一事实中推断出来,除非明确说明,而且到目前为止我的经验是我期望在那里做的事情,那里。 I don't know Django and haven't used it on GAE (apart from templates), so I can't comment on that. 我不知道Django并没有在GAE上使用它(除了模板),所以我不能对此发表评论。

Personally I probably wouldn't target LAMP (where P = Django) with the intention of migrating to GAE later. 就个人而言,我可能不会以LAMP(其中P = Django)为目标,以便稍后迁移到GAE。 I'd develop for both together, and try to ensure if possible that the differences are kept to the very top (configuration) and the very bottom (data model). 我会一起开发,并尽可能确保差异保持在最顶层(配置)和最底层(数据模型)。 The GAE version doesn't necessarily have to be perfect, as long as you know how to make it perfect should you need it. GAE版本不一定非常完美,只要您知道如何在需要时使其完美。

It's not guaranteed that this is faster than writing and then porting, but my guess is it normally will be. 不能保证这比写入和移植更快,但我的猜测通常是这样。 The easiest way to spot any differences is to run the code, rather than relying on not missing anything in the GAE docs, so you'll likely save some mistakes that need to be unpicked. 发现任何差异的最简单方法是运行代码,而不是依赖于GAE文档中没有遗漏任何内容,因此您可能会保存一些需要删除的错误。 The Python SDK is a fairly good approximation to the real App Engine, so all or most of your tests can be run locally most of the time. Python SDK与真正的App Engine相当接近,因此大多数时候您可以在本地运行所有或大部分测试。

Of course if you eventually decide not to port then you've done unnecessary work, so you have to think about the probability of that happening, and whether you'd consider the GAE development to be a waste of your time if it's not needed. 当然,如果你最终决定不进行移植,那么你已经完成了不必要的工作,所以你必须考虑发生这种情况的可能性,以及你是否认为GAE开发是浪费你的时间,如果不需要的话。

Basically, you will change the data model base class and some APIs if you use them (PIL, urllib2, etc). 基本上,如果您使用它们(PIL,urllib2等),您将更改数据模型基类和一些API。

If your goal is app-engine, I would use the app engine helper http://code.google.com/appengine/articles/appengine_helper_for_django.html . 如果您的目标是app-engine,我会使用应用引擎助手http://code.google.com/appengine/articles/appengine_helper_for_django.html It can run it on your server with a file based DB and then push it to app-engine with no changes. 它可以使用基于文件的数据库在您的服务器上运行它,然后将其推送到app-engine而不进行任何更改。

It sounds like you have awareness of the major limitation in building/migrating your app -- that AppEngine doesn't support Django's ORM. 听起来您已经意识到构建/迁移应用程序的主要限制 - AppEngine不支持Django的ORM。

Keep in mind that this doesn't just affect the code you write yourself -- it also limits your ability to use a lot of existing Django code. 请记住,这不仅会影响您自己编写的代码 - 它还会限制您使用大量现有Django代码的能力。 That includes other applications (such as the built-in admin and auth apps) and ORM-based features such as generic views . 这包括其他应用程序(例如内置管理员和auth应用程序)和基于ORM的功能,例如通用视图

There are a few things that you can't do on the App Engine that you can do on your own server like uploading of files. 您可以在自己的服务器上执行一些在App Engine上无法执行的操作,例如上载文件。 On the App Engine you kinda have to upload it and store the datastore which can cause a few problems. 在App Engine上,您必须上传它并存储可能导致一些问题的数据存储。

Other than that it should be fine from the Presentation part. 除此之外,演示文稿部分应该没问题。 There are a number of other little things that are better on your own dedicated server but I think eventually a lot of those things will be in the App Engine 在你自己的专用服务器上还有很多其他的小东西,但我认为最终很多这些东西都会出现在App Engine中

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

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