續前文,因為這想詳細交代一下,所以就獨立一篇來..
因為要在模板中使用迴圈,列出資料,所以就出現了要將資料同時作出轉換..
但發現他本身好像並沒有提供相關的函數吧,所以就只好自己寫..誰不知道出錯..
原來在這 Python 的模板中需要使用函式的話,就要自己註冊這函數,才可在模板中使用?
上網找了很多東西,試了很多 Keyword 都沒效,最後隨著深入的考古..終於解決了..一個小時的結論 = =
多的不說自記錄一下 (這本就不該寫太多!)
1 2 3 4 5 6 7 8 9 10 11 12
|
from google.appengine.ext import webapp
register = webapp.template.create_template_register()
def dateFormat(value): return (value + timedelta(hours=+8)).strftime("%Y-%m-%d %H:%M:%S")
register.filter(dateFormat)
|
1 2 3 4
|
webapp.template.register_template_library('common.templatefilters')
|
最後一小點結論,如果明天真的有空,應該要將整個程序分離開來..
直接使用 django 這 framework 應該比較好吧?..不過工程就..Orz
GAE 的模板過濾器解決方法參考至 :
http://groups.google.com/group/google-appengine/browse_thread/thread/494f4cf0698d463f
http://daily.profeth.de/2008/04/using-custom-django-template-helpers.html