我在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