欢迎使用我的 在线工具

小D

读历史、看小说、写程序都是我所爱。技术不好,头脑不灵光,靠的是兴趣。
随笔 - 35, 文章 - 25, 评论 - 13, 引用 - 0
数据加载中……

使用BAE的基于Web.py的简单博客程序

      首先这个博客程序十分简单,就是一个首页,一个文章详情页面,一个登陆页面,还有一个编辑/添加的页面。
可以通过 http://codecos.com 访问。github地址:https://github.com/daimin/tolog

1. 关于BAE

      部署在BAE上面,BAE还是很给力的。对于我等舍不得花钱买空间的码农来说,还是一个福音,而且它给得免费配额是很大的,起码比SAE大,速度也不错,支持的语言环境也比较多,
本人在上面就部署了PHP,node.js和Python三个。
      不过需要配置URL,其实就和在web.py里面配置的差不多,不过就是要我们还要在BAE里面(app.conf)再设置一下罢了。
      
  - url : /(\d*)
     script : index.py
  - url : /new
    script : index.py
  - url : /view/(\d*)
    script : index.py
  - url : /delete/(\d+)
    script : index.py
  - url : /login/?
    script : index.py
  - url : /edit/(\d+)
    script : index.py
  - url : /tag/(\d+)/?(\d*)
    script : index.py
  - url : /search/([^\s/]+)/?(\d*)
    script : index.py
  - url : /date/(\d+)/?(\d*)
    script : index.py
  - url : /month/(\d+)/?(\d*)
    script : index.py
  - url : /year/(\d+)/?(\d*)
    script : index.py
  - url : logout/?
    script : index.py
  - url : /static/(.*)
    script : index.py
    
         只不过它的文件系统不能持久化,所以至于上面图片等,可以考虑存到数据库,或者是采用其他的图片服务。

2. 关于Web.py

        首先沉重悼念 Aaron Swartz。
        web.py是很简单的,像这样:
urls = (
    r'/(\d*)''Index',
)
就行了,Index是一个类,你可以定义一个POST和GET函数,它们分别对象POST和GET请求。
class Index:

    def GET(self, page):
        """ Show page """
        #做你想做的
        return render.index(传数据)
    
    def POST(self, page):
        return render.index(传数据)
     web.py虽然很简单但是运行效率的确不怎样,但是做一个个人的博客之内的还是足够了的,而且关键还要看怎样优化了。

3. 结合web.py和BAE

     在BAE上面运行web.py有一些特许的配置。
     
mysql:
 dbname = "mytestdb"
 mydb = MySQLdb.connect(
      host   = const.MYSQL_HOST,
      port   = int(const.MYSQL_PORT),
      user   = const.MYSQL_USER,
      passwd = const.MYSQL_PASS,
      db = dbname)

   
运行web.py:
app = web.application(urls, globals()).wsgifunc()
from bae.core.wsgi import WSGIApplication
application = WSGIApplication(app)

posted on 2013-07-29 15:01 vagasnail 阅读(780) 评论(0)  编辑  收藏 所属分类: 动态语言服务器python


只有注册用户登录后才能发表评论。


网站导航: