在App Engine下运行Django 1.2

我不知道[url=https://appengine.google.com/]App Engine[/url]是从什么时候开始默认支持Django 1.2的,好像支持的时间不长,我懒得去求证了,反正你去下载最新的SDK准支持,保准支持。要在App Engine下运行Django通常有两种方法:一种是使用[url=https://bitbucket.org/wkornewald/django-nonrel/wiki/Home]django-nonrel[/url],它是django的一个nosql分支,它可能不太稳定,但如果你要将已有应用移植到app engine上,这是最快捷的方法,你仍然可以使用django的models, forms,应用几乎不需要改动,当然由于两者使用不同类型的数据库,数据存储模型可能要针对app engine微调一下。第二种方法就是使用标准的django,这种方法的缺点是不能再使用django的models,app engine有一套自己的数据模型。这里讨论后一种方法。

虽然app engine自带django,但使用django并不那么简单,当然这么大众的问题早就已经有解决方案了,那就是[url=http://code.google.com/p/google-app-engine-django/]google-app-engine-django[/url],从[url=http://code.google.com/p/google-app-engine-django/downloads/detail?name=appengine_helper_for_django-r109.zip&can=2&q=]这里[/url]下载压缩包,将它解压。

将解压的目录appengine_helper_for_django改成你应用的名称,例如shared-accounting,同时修改app.yaml中application的值为应用名称。appengine helper最多只支持django 1.1,要支持1.2需要修改它的源代码。编辑appengine_django目录下的__init__.py,在171行将它改成(在'1.1'前面加上'1.2'):

for check_version in ('1.2', '1.1', '1.0'):
try:
use_library('django', check_version)
return
except UnacceptableVersionError:
pass


基本上就是这么简单,然后就可以运行: python manage.py runserver启动服务器,然后就可以在浏览器在访问http://localhost:8000。然后可以用python manage.py startapp创建新的app,之后一切与标准django类似。实际运行中还有一些问题要注意。


[b][size=medium]Session管理[/size][/b]

只要有用户,基本上就会有session,在gae中要开启session很简单,和标准django一样,只需要在settings.py中开启SessionMiddleware就可以了。


[b][size=medium]用户Authentication[/size][/b]

appengine helper替换掉标准django中的authentication,其内部实现使用app engine的认证,这意味着在可以使用gmail帐户(以及其它支持openid的账户),如果你的应用是这样的,那么只需要启用AuthenticationMiddleware就可以了。如果应用想要自己注册帐户,那么首先要禁用appengine替换标准的authentication,还是在appengine_django目录下的__init__.py,将第557行的InstallAuthentication(settings)注释掉,然后从头实现你的用户模型,实现AuthenticationBackend,并在settings.py中启用。

AUTHENTICATION_BACKENDS = ( "your authentication backend",)


最后实现用户注册、登陆等view,整个过程工作量不小。大家可以看我后面给出的demo。


[b][size=medium]数据访问[/size][/b]

app engine和django自带的数据模型有很大不同,其内部一个是BigTable,一个是MySQL等关系型数据库。app engine的数据模型使用的是google.appengine.ext.db.Model,appengine helper提供一层薄的封装appengine_django.models.BaseModel,我没有用BaseModel直接使用appengine的[url=http://code.google.com/appengine/docs/python/datastore/]db.Model[/url],db.Model其实在很大程序上模仿的是django,它甚至还有和django的ModelForm相对应的google.appengine.ext.db.djangoforms。


[b][size=medium]时区[/size][/b]

app engine内部都使用utc时间,我刚开始将settings的TIMEZONE设置成'Asia/Shanghai',结果碰到很诡异的问题,有时时间返回的是本地时间,有时返回的是utc时间。所以在开发app engine应用时最好数据存储都使用utc时间,然后在展现时将它转成本地时间。


说了这么多,希望能给大家在app engine上开发django程序有一些帮助。我写了一个小网站(不仅仅是个demo),它是帮助管理合租、聚餐等集体费用的一个工具性网站,网址在是[url=http://shared-accounting.appspot.com/]http://shared-accounting.appspot.com[/url](需要翻~~墙,推荐IPv6,方法自行google)。代码在[url=http://code.google.com/p/shared-accounting/source/browse/]这里[/url]。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
About Wouldn't your prefer to let your users speak instead of making them type? This plugin uses OS components for speech recognition and send it to your Unity scripts as String objects. Plugin supports: - Android >= 3.0 (haven’t tested below, it might work though… ), - iOS >= 10.0. That doesn’t mean you can’t target iOS lower than 10 - you simply have to prepare fallback code to cover cases when user doesn’t have access to speech recognition (SpeechRecognizer.EngineExists() for the help!). Keep in mind that both iOS and Android might use Internet connection for speech detection, which means it might fail in case there’s no active connection. Plugin doesn’t work in Editor! You have to run your app on real iOS or Android device. MOBILE SPEECH RECOGNIZER - UNITY PLUGIN ?2 Quick Start Open example scene Go to KKSpeechRecognizer/Example folder inside Unity and open ExampleScene: It shows basic usage of a plugin, which is: 1. Detecting if speech recognition exists on user’s device (keep in mind that it won’t be available on e.g. iOS 9 or old Android phones), 2. If it exists, and user clicks on “Start Recording” button it listens for recognized text and displays it on a screen, 3. On Android, speech recognition automatically detects when user finishes speaking, but on iOS we have to wait for user clicking “Stop Recording” to finish whole process (i.e. get final results). Before running it on Android or iOS device you have to… Setup permissions iOS After generating Xcode project (keep in mind that you have to use Xcode 8 or higher) you have to add two permissions keys to your project: MOBILE SPEECH RECOGNIZER - UNITY PLUGIN ?3 NSMicrophoneUsageDescription explanation from Apple docs: This key lets you describe the reason your app accesses any of the the device’s microphones. When the system prompts the user to allow access, this string is displayed as part of the alert. NSSpeechRecognitionUsageDescription explanation from Apple docs: This key lets you describe the reason y

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值