templates - Why do trim_blocks and lstrip_blocks under Flask/OpenShift produce different results when tested online, compared when to tested locally? -


i'm writing simple web app using flask, hosted on openshift. want control whitespace in template files, jinja command lines removed in:

<div> {% if true %}     yay {% endif %} </div> 

...producing:

<div>     yay </div> 

the jinja docs @ http://jinja2.readthedocs.io/en/latest/templates.html#whitespace-control (and other sources) imply should

flask_app_obj.jinja_env.lstrip_blocks = true flask_app_obj.jinja_env.trim_blocks = true 

...which have done, in init.py file app package. however, yields inconsistent behaviour when test locally , on openshift; locally, expected result (i.e. jinja commands removed, if never there), , on openshift get:

<div>         yay     </div> 

consulting docs , researching similar whitespace issues, seemed there 2 causes of inconsistency. either there strange going on newlines, local machine using different scheme compared hosted openshift environment (along lines of https://superuser.com/questions/374028/how-are-n-and-r-handled-differently-on-linux-and-windows) , produces different whitespace-culling behaviour when template generated @ openshift end, or, changing jinja2 environment object when shared or after template has been loaded, violates docs quote:

instances of class may modified if not shared , if no template loaded far. modifications on environments after first template loaded lead surprising effects , undefined behaviour.

... along lines of stripping whitespace in jinja2 & flask...why still need minus sign? , trimming blocks using whitespace control jinja2 template.

plausible causes, in doubt reason strange openshift-side template behaviour. if had operated on jinja environment early, surely see incorrect template output locally (which don't, expected result locally). indeed, it's in init.py file set lstrip_blocks , trim_blocks true. doubt it's newline issue since developing on os x, , openshift environment *nix, both environments should using same newline scheme.

given above, have no more theories why getting inconsistent results between openshift testing , local testing. questions these: have set jinja options in wrong place , should somewhere other init.py? modifying jinja2 environment inappropriately? method of setting jinja2 options plain wrong? perhaps should using other avenue set such options other

flask_app_obj.jinja_env.lstrip_blocks = true flask_app_obj.jinja_env.trim_blocks = true 

thanks answering.

if using git push deploy code, might check having git fix line endings unix/linux style, described here: https://help.github.com/articles/dealing-with-line-endings/


Comments