我在我的集合.py公司名称:
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__),'html').replace("\\","/"),
)
在请求处理程序中:
^{pr2}$我希望,模板将从/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,结果是一样的。在
我做错什么了?在
在stock GAE中,Django的
TEMPLATE_DIRS
功能没有使用。我执行以下操作,基本上是直接从the templates docs开始的:在这种情况下,'索引.html'是生活在应用程序根目录下的资源。如果模板在应用程序的目录中,请相应地调整
os.path.join()
。在因此,webapp引擎中的问题是:“\u load_user_django”方法(来自我系统上的C:\Program Files(x86)\Google\Google_appengine\Google\appengine\ext\webapp)覆盖了用户定义的TEMPLATE_DIRS变量:
因此,当get_template_sources方法(从文件系统.py)尝试调用“safe_join(template_dir,template_name)”,但失败,并出现以下错误:
^{pr2}$默认情况下,django在app_name/templates/app_name中查找模板/模板.html(对,app_name重复)
所以在您的例子中,它会在project\u dir/html/project\u dir中查找模板/模板.html,假设project\u dir与您的django应用程序名称相同。在
相关问题 更多 >
编程相关推荐