我在settins.py下面的代碼:GAE模板不起作用
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__),'html').replace("\\","/"),
)
,並在請求處理程序:
r = template.render('mt.html', {'some_content':blabla,})
我期待,該模板會從/project_dir/html/mt.html文件加載。 但它失敗,出現以下錯誤:
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\_webapp25.py", line 701, in __call__
handler.get(*groups)
File "D:\ap\pz4\pz4\main.py", line 33, in get
x8= template.render(fn, {'some_content':blabla,})
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\template.py", line 91, in render
t = _load_user_django(template_path, debug)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\template.py", line 113, in _load_user_django
template = django.template.loader.get_template(file_name)
File "C:\Program Files (x86)\Google\google_appengine\lib\django_1_3\django\template\loader.py", line 157, in get_template
template, origin = find_template(template_name)
File "C:\Program Files (x86)\Google\google_appengine\lib\django_1_3\django\template\loader.py", line 138, in find_template
raise TemplateDoesNotExist(name)
TemplateDoesNotExist: mt.html
在同一時間,它工作正常,當我把它直接使用文件夾定義:
r = template.render(os.path.join(os.path.dirname(__file__),'html/mt.html').replace("\\","/"),{'some_content':blabla,})
GAE是1.6.3(本地), django版本(使用use_library('django','xxx'))檢查了0.96,1.2和1.3,結果是一樣的。
我在做什麼錯了?
我把 「mt.html」 到下列文件夾: APP_ROOT APP_ROOT/HTML APP_ROOT/HTML/APP_NAME 但它仍然沒有工作。 – user1276220 2012-03-17 22:47:48
文檔可能會幫助你比我更多。 https://docs.djangoproject。com/en/dev/ref/templates/api/ 它看起來像我在錯誤的軌道上,我在我的模板中使用子文件夾,但你沒有這樣做。通過添加一行來在堆棧跟蹤中指定的適當位置打印出template_path或file_name,應該非常容易進行調試。 – dragonx 2012-03-18 02:32:06