django - Unrelenting TemplateSyntaxErrors -
update #7:
i removed first line , put in place second line below copied jinja2 link jinja2 install docs. still error below.
# google.appengine.ext.webapp import template jinja2 import template file "/users/brian/googleapps/youpoll/views.py", line 271, in self.response.out.write(template.render(path, template_values)) nameerror: global name 'template' not defined info 2012-07-08 22:43:53,053 dev_appserver.py:2952] "get /?id=testbschott http/1.1" 500
this appengine worked little while ago non-django code in template files.
furthermore, if execute following code in gae interactive console, works, though contains {%- if ... -%} code think unique jinja2, not django.
from jinja2 import template template = template('{%- if true -%}hello {{ name }}!{% endif %}') print template.render(name='john doe')
update #6:
ok, found variable template being defined. it's below.
jinja_environment.filters['datetimeformat'] = datetimeformat class basehandler(webapp2.requesthandler): @webapp2.cached_property def jinja2(self): return jinja2.get_jinja2(app=self.app) def render_template( self, filename, template_values, **template_args ): template = jinja_environment.get_template(filename) self.response.out.write(template.render(template_values))
update #5:
here imports in views.py:
import jinja2 import os import webapp2 import logging import datetime google.appengine.ext import db google.appengine.api import users google.appengine.ext.webapp import template google.appengine.ext.webapp.util import run_wsgi_app google.appengine.api import images # jinja2 import environment, packageloader models import qa, pq template_dir = os.path.join(os.path.dirname(__file__), 'templates') jinja_environment = \ jinja2.environment(loader=jinja2.filesystemloader(template_dir))
my use of template_values below in code posted. 2 of imports mention webapp, not webapp2. if change first 1 webapp2 error.
file "/users/brian/googleapps/youpoll/views.py", line 9, in <module> google.appengine.ext.webapp2 import template importerror: no module named webapp2 info 2012-07-08 18:44:18,972 dev_appserver.py:2952] "get /?id=testbschott http/1.1" 500
and if remove line the error.
file "/users/brian/googleapps/youpoll/views.py", line 272, in self.response.out.write(template.render(path, template_values)) nameerror: global name 'template' not defined info 2012-07-08 18:30:52,733 dev_appserver.py:2952] "get /?id=testbschott http/1.1" 500
do see can do? did give info need?
update #3: if remove these 5 jinja2 sequences/phrases html form works fine. there no syntax error these 5 sequences/phrases. used work fine. , have added below in first update traceback includes django, although not using django -- jinja. other error making?
i have included @ bottom html page prior removing sequences/phrases above.
1
{% choice in p.choices -%} {% if not loop.first %} ,{% endif %} {% if loop.last %} or {% endif %} {{ choice }} {%- endfor %}.
2 {% choice in p.choices %} {% if not loop.first %} ,{% endif %} {% if loop.last %} or {% endif %} {{ choice }} {% endfor %}.
3
{{ q.answers|sum() }}
4
q.date|datetimeformat('%d-%m-%y')
5
q.modified|datetimeformat('%d-%m-%y')
end of update #3
this phrase occurs before errors, works fine.
{% if p.purpose %} </p> <p> purpose of questionnaire {{ p.purpose }}. </p> {% endif %}
but next phrase throws error (apparently).
{% choice in p.choices -%} {% if not loop.first %} ,{% endif %} {% if loop.last %} or {% endif %} {{ choice }} {%- endfor %}.
next error.
update #2: if revise "errant" 'for' statement, removing space control '-'s, system still moves on next error below, , yet '-'s not errors.
error 2012-07-06 21:46:07,107 webapp2.py:1553] 'for' statements should use format 'for x in y': choice in p.choices - traceback (most recent call last):
update #1:
file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/lib/webapp2/webapp2.py", line 1536, in __call__ rv = self.handle_exception(request, response, e) file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/lib/webapp2/webapp2.py", line 1530, in __call__ rv = self.router.dispatch(request, response) file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/lib/webapp2/webapp2.py", line 1278, in default_dispatcher return route.handler_adapter(request, response) file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/lib/webapp2/webapp2.py", line 1102, in __call__ return handler.dispatch() file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/lib/webapp2/webapp2.py", line 572, in dispatch return self.handle_exception(e, self.app.debug) file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/lib/webapp2/webapp2.py", line 570, in dispatch return method(*args, **kwargs) file "/users/brian/googleapps/youpoll/views.py", line 272, in self.response.out.write(template.render(path, template_values)) file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/google/appengine/ext/webapp/template.py", line 89, in render t = _load_internal_django(template_path, debug) file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/google/appengine/ext/webapp/template.py", line 163, in _load_internal_django template = django.template.loader.get_template(file_name) file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/google/appengine/_internal/django/template/loader.py", line 160, in get_template template = get_template_from_string(template, origin, template_name) file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/google/appengine/_internal/django/template/loader.py", line 168, in get_template_from_string return template(source, origin, name) file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/google/appengine/_internal/django/template/__init__.py", line 158, in __init__ self.nodelist = compile_string(template_string, origin) file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/google/appengine/_internal/django/template/__init__.py", line 186, in compile_string return parser.parse() file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/google/appengine/_internal/django/template/__init__.py", line 281, in parse compiled_result = compile_func(self, token) file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/google/appengine/_internal/django/template/loader_tags.py", line 195, in do_extends nodelist = parser.parse() file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/google/appengine/_internal/django/template/__init__.py", line 281, in parse compiled_result = compile_func(self, token) file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/google/appengine/_internal/django/template/loader_tags.py", line 173, in do_block nodelist = parser.parse(('endblock', 'endblock %s' % block_name)) file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/google/appengine/_internal/django/template/__init__.py", line 281, in parse compiled_result = compile_func(self, token) file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/google/appengine/_internal/django/template/defaulttags.py", line 684, in do_for " 'for x in y': %s" % token.contents) templatesyntaxerror: 'for' statements should use format 'for x in y': choice in p.choices - info 2012-07-06 21:46:07,117 dev_appserver.py:2952] "get /?id=testbschott http/1.1" 500 -
and if remove phrase template 1 throws error (after skipping on other (%ifs , {%fors ).
{% q in qs|sort(attribute='seqnum') %}
next error.
error 2012-07-06 21:48:38,177 webapp2.py:1553] invalid filter: 'sort' traceback (most recent call last): ... templatesyntaxerror: invalid filter: 'sort' info 2012-07-06 21:44:03,051 dev_appserver.py:2952] "get /?id=testbschott http/1.1" 500 -
and if remove phrase template 1 throws error (after skipping on other (%ifs , {%fors ).
<td align="right"> {{ q.answers|sum() }} </td>
and if remove phrase template 1 throws error, too.
error 2012-07-06 21:36:07,650 webapp2.py:1553] invalid filter: 'sum' traceback (most recent call last): ... templatesyntaxerror: invalid filter: 'sum'
etc. looks signal else wrong. don't have clue. template worked little before, has stopped working, suspect there error in python code cause cannot imagine start looking.
btw, traceback mentions django often, when using jinja2, suppose irrelevant.
below python code use feed template. have left in logging info show of debugging have done.
qs = db.query(qa) qs.ancestor(person) qs.filter('deleterequested =', false) qs.run() item in qs: logging.info("2 seqnum %d" % item.seqnum) item in person.choices: logging.info("2 choice %s" % item ) logging.info("2 title %s" % person.title ) logging.info("2 person.key()%s" % person.key()) # template_values = {'id_id':person.key(), template_values = { 'p': person, 'qs': qs } path = os.path.join(template_dir, 'table.html') logging.info("here after revise" ) self.response.out.write(template.render(path, template_values))
update #4:
following listing of html page failing.
{% extends "base.html" %} {% block content %} <center> <h1>make preferences <span class="emph">{{p.id|escape}}</span> known here</h1> {% if p.title %} </center> <p><h2> title of questionnaire is: {{ p.title }}.</h2> </p> </center> {% endif %} <br /> <div id="inputdata"> {% if p.purpose %} <p> purpose of questionnaire is: {{ p.purpose }}. </p> {% endif %} <p>this participative preferences survey: not answer questions, supply questions answer. </p> <ol> <li> answer existing questions, click on "radio" button in corresponding rows of table: {% choice in p.choices -%} {% if not loop.first %} ,{% endif %} {% if loop.last %} or {% endif %} {{ choice }} {%- endfor %}. </li> <li> after answering questions, @ bottom of page click "submit" button register answers. </li> </ol> </div> <br /> <div id="inputdata"> <p>to supply new question or statement, click <a href="/add_question?id={{ p.id }}"><span class="emph">here</span></a>. @ present time there no automated mechanism editing or erasing existing question. </p> <br /> <p>the question numbers (no's) used arrange questions. place question in list number choose. </p> </div> {% if not p.moreinfo == 'none' %} <p> {{ p.moreinfo }} </p> {% endif %} <form action="table" method="post" enctype="multipart/form-data"> <input type="hidden" name="id" value="{{p.id|escape}}"></input><br/> <table border="1" cellpadding="2" cellspacing="0" class="sortable" id="unique-id"> <thead> <tr> <td>no</td> <td>question</td> <td> total </td> {% choice in p.choices %} <td bgcolor="#fef886"> {{ choice }} </td> {% endfor %} <td> created </td> <td> last answered </td> </tr></thead> <tbody> {% if qs %} {% q in qs|sort(attribute='seqnum') %} <tr> <td align="right"> {{ q.seqnum }} </td> <td> {{ q.question }} </td> <td align="right"> {{ q.answers|sum() }} </td> {# <td> {{ q.total }} </td> #} {% answer in q.answers %} <td bgcolor="#fef886"> <input type="radio" name="{{q.seqnum}}" value="{{loop.index}}" /> {{ answer }} </td> {% endfor %} <td>{{ q.date|datetimeformat('%d-%m-%y') }}</td> <td>{{ q.modified|datetimeformat('%d-%m-%y')}}</td> </tr> {% endfor %} {% endif %} </tbody> </table> <br /> <div id="inputdata"> <p>to remember own choices, print page before reloading</p> </div> <center> <input type="submit" name="submit" value="submit" /> </center> </form> <script src="/static/javascript/sorttable.js" type="text/javascript"></script> {% endblock content %}
wooble answered question commenting rid of google.appengine.ext.webapp import template
, replace from jinja2 import template
, had error may have caused original problem. used self.response.out.write(template.render(path, template_values))
instead of self.render_template('table.html', template_values )
@ 1 point.
the key problem gae using django when thought using jinja2 , wooble keyed on fact mentioned casually in original question.
(so hope wooble gets credit answer.)
Comments
Post a Comment