鉴于bae与sae是国内少有的app engine. 且bae又后来居上、可用git版本管理,因而试用此平台挂一个测试Python Django应用。
但百度云的Python文档还真是少的可怜,又没怎么维护,都让我怀疑到底这货百度要不要了。文档传送门。bae支持Django 1.4版本,主流是1.5,将就着用。
http://901314.duapp.com/就是拙做,页面中惟一的超连接hello的实现方式是调用Django中的一个app。依着简陋的文档修修补补push两回后,超连接hello竟然是404错误,顿时乱了手脚。这么简单的测试也出错,但bae又不给调试信息,因而乱七八糟的搞了一会仍是没见效。最后想一想,多是git上传了.pyc字节码文件捣乱,删除bae上的全部代码,从新push一份干净的demo,终于hello连接能够跳转了,记录庆祝下,SE来爬个人网页吧哈哈。之后试试动态生成内容。
示例源码http://git.oschina.net/397667796/bae_django,来fork吧。 php
ps: bae好像也会出调试信息,把调试打开,访问不存在的地址http://901314.duapp.com/hellos,出现下面与本地同样的debug信息,那为何以前超连接出问题不出debug信息呢?==! html
Page not found (404) Request Method: GET Request URL: http://901314.duapp.com/hellos Using the URLconf defined in bae_django.urls, Django tried these URL patterns, in this order: ^$ [name='home'] ^hello/$ [name='hello'] The current URL, hellos, didn't match any of these. You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
2013.07.10 更新:
源代码增长BAE版本1,测试调用非默认的Django 1.4库,而是调用应用目录下的Django 1.5.1库,测试成功。参考http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/python/faq。但总共几M的git包,竟push到BAE失败,提示以下。哪位知道如何解决的,多谢回复。
python
Counting objects: 4592, done. Delta compression using up to 2 threads. Compressing objects: 100% (2499/2499), done. efrror: RPC failed; result=22, HTTP code = 411| 1.23 MiB/s Watal: The remote end hung up unexpectedly Writing objects: 100% (4588/4588), 3.04 MiB | 957 KiB/s, done. Total 4588 (delta 1209), reused 1 (delta 0) fatal: The remote end hung up unexpectedly Everything up-to-date
2013.07.11 更新:
今天折腾半天,终于弄清“超连接hello竟然是404错误”的缘由,在于app.conf文件,出现错误的静态资源文件配置以下。
(2013.07.11晚更新:此配置是对未使用Django框架,全部路由由app.conf处理,不管是目录(/)、静态文件(/static/$1)、仍是(动态脚本)):
git
handlers: - url : / script: index.py - url : /(.*).py script: $1.py - url : /static/(.*) script: /static/$1 - expire : .jpg modify 10 years - expire : .swf modify 10 years - expire : .png modify 10 years - expire : .gif modify 10 years - expire : .JPG modify 10 years - expire : .ico modify 10 years而正确的配置文件是下面这样的,区别在于对index.py的映射路径。
handlers: - url : /static/(.*) script : /static/$1 - url : /.* script : index.py - expire : .jpg modify 10 years - expire : .swf modify 10 years - expire : .png modify 10 years - expire : .gif modify 10 years - expire : .JPG modify 10 years - expire : .ico modify 10 years坐等大神们帮忙解释。