Django包含模板问题,从0.96到1.2 [英] Django include templates problem, from 0.96 to 1.2

查看:116
本文介绍了Django包含模板问题,从0.96到1.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用谷歌应用程序引擎,在0.96我没有问题,包括一个模板如下

  {%include。 ./header.html%

但是,在1.2以上的代码不起作用? p>

任何想法?

解决方案

原因是 google.appengine.ext.webapp.template.render 不使用任何用户可配置的 TEMPLATE_DIRS 。相反,它发明自己的 TEMPLATE_DIRS byt取得给定模板的目录,并使用它在 TEMPLATE_DIRS 中。这意味着如果您调用 render(foo / bar / fie),将使用 foo / bar 作为模板目录和查找文件。



现在,从0.96到1.2的更改是使用 os.path.join切换文件查找使用 django.utils._os.safe_join 不允许使用 ../



我没有看到任何明显的方法。您似乎必须直接在模板目录中调用 render ,而不是在子目录中。


I using google app engine, in 0.96 I have no problem to include a template as following

{% include "../header.html" %}

However, in 1.2 the code above not functioning??

Any idea?

解决方案

The reason is that google.appengine.ext.webapp.template.render doesn't use any user-configurable TEMPLATE_DIRS. Instead it invents its own TEMPLATE_DIRS byt taking the directory of the given template and using that at TEMPLATE_DIRS. This means if you call render("foo/bar/fie") it will use foo/bar as your template directory and look up files from there.

Now, the change from 0.96 til 1.2 is that the file lookup switched from using os.path.join to using django.utils._os.safe_join which does not allow escape from the base directory using ../.

I don't see any obvious way around this. It seems like you must call render with a file directly in your template directory and not in a subdirectory.

这篇关于Django包含模板问题,从0.96到1.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆