首先這個博客程序十分簡單,就是一個首頁,一個文章詳情頁面,一個登陸頁面,還有一個編輯/添加的頁面。
可以通過
http://codecos.com 訪問。github地址:
https://github.com/daimin/tolog1. 關于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)