Django includes a problem with templates, from 0.96 to 1.2

I use the Google engine, at 0.96. I have no problem turning the template into line with

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

However in 1.2 the code above doesnโ€™t work ??

Any idea?

+4
source share
3 answers

The reason is that google.appengine.ext.webapp.template.render does not use user custom TEMPLATE_DIRS . Instead, he invents his own TEMPLATE_DIRS byt, taking the directory of this template and using it in TEMPLATE_DIRS . This means that if you call render("foo/bar/fie") , it will use foo/bar as the directory for your template and look for files there.

Now the change from 0.96 to 1.2 means that the file search has switched from using os.path.join to using django.utils._os.safe_join , which does not allow you to exit the base directory using ../ .

I do not see the obvious path here. It looks like you should call render with the file directly in your templates directory, and not in a subdirectory.

+3
source

dkagedal is true in evaluating the problem, but there is an easy workaround if you are not averse to monkeypatching:

 try: # Bypass Django safe_join for template paths since App Engine sandboxes the # filesystem anyway, and safe_join won't allow relative includes because # webapp.template always sets the template parent directory as the "root", # rather than the app real root directory. from django.utils import _os _os.safe_join = os.path.join except ImportError: pass # App is using a version of Django that doesn't use safe_join, it OK. 
+2
source

It seems strange that this does not work - this is the correct syntax for the tag ...

How does it not work? Do not enter data at all? Error message?

Is header.html just regular html body sections? or is it a full standalone html page? (i.e. does it have html, head, body, tags, etc., or just h, p, etc.?)

Perhaps try using the tag {% ssi%} as described here: SSI Template Template

0
source

Source: https://habr.com/ru/post/1341667/


All Articles