mako

Printing lists with Mako template (Django Join tag)

廉价感情. 提交于 2019-12-14 02:27:19
问题 In this article Django templates like this {% for i in mylist %} <tr> <td>{{i.replist|join:"</td><td>" }}</td> </tr> {% endfor %} prints the list mylist which is an object. Can this be done in Mako? Thanks. EDIT class Rep(db.Model): author = db.UserProperty() replist = db.ListProperty(str) unique = db.ListProperty(str) date = db.DateTimeProperty(auto_now_add=True) class MainPage(webapp.RequestHandler): def get(self): user = users.get_current_user() greeting = None if user: greeting = (

How to reference multi-word dictionary key in mako?

可紊 提交于 2019-12-13 20:26:36
问题 I am passing a csv file to Mako via csv.DictReader , and the dictionary uses row headers for keys. Some of these have names like 'Entry Id'. Mako throws out errors when I try to reference these multi-word keys in a template. Specifically, the error message is mako.exceptions.SyntaxException: (SyntaxError) invalid syntax (<unknown>, line 1) . The following code demonstrates the issue I am experiencing: from mako.template import Template mydata = {'foo': 'bar', 'better foo': 'beach bar'}

Reused variable in Mako template cause “UnboundLocalError: local variable 'xyz' referenced before assignment”

走远了吗. 提交于 2019-12-13 01:26:04
问题 I have this "funny" issue. I know this error message is found in a lot of places, but I couldn't find one explicitely related to Mako. In a Mako template, I have (snippet): <%inherit file="other.mako"/> <%def name="my_method()">Search for ${label}</%def> [...] <h2>${label.capitalize()} found: ${len(l)}</h2> ... <ol> % for (label, field_name) in some_list: <li>${label}: ${field_name}</li> % endfor </ol> and I would get the error: UnboundLocalError: local variable 'label' referenced before

Sprox form with Turbogears, using Mako, only displays plain text

余生长醉 提交于 2019-12-11 03:44:48
问题 I'm generating a Sprox form with Turbogears 2.1 and trying to display it in a Mako template. Here is my code: To define the form: class NewUserForm(AddRecordForm): __model__ = User newuserform = NewUserForm(DBSession) The controller definition that assigns the form and calls the template: @expose('limelight.modules.users.templates.register') def register(self, **kw): tmpl_context.register_form = newuserform return dict(value=kw) And the relevant template code: ${tmpl_context.register_form

how to deal with unicode in mako?

爱⌒轻易说出口 提交于 2019-12-08 16:03:27
问题 I constantly get this error using mako: UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0' in position 6: ordinal not in range(128) I've told mako I'm using unicode in any possible way: mylookup = TemplateLookup( directories=['plugins/stl/templates'], input_encoding='utf-8', output_encoding='utf-8', default_filters=['decode.utf8'], encoding_errors='replace') self.template = Template(self.getTemplate(), lookup=mylookup, module_directory=tempfile.gettempdir(), input_encoding='utf

Can't get Mako engine in CherryPy to work

荒凉一梦 提交于 2019-12-08 09:21:54
问题 I need to set up a server using CherryPy and the Mako Template Engine, though I can't get the latter to work. I started to integrate the code from >>here<< into my working CherryPy setup. Though in the end, I only see "Hello, ${username}!" as text instead of the inserted variable. Other information or examples I found via search or Google didn't solve that as well. Since the code is quite long, I use pastebin to show it. server.py app/application.py << I put another version of the index

How to change the mako substitution delimiter characters?

守給你的承諾、 提交于 2019-12-06 08:29:54
问题 Is it possible to change the "delimiter tags" for expression substitution in the Python Mako templating library? If so, how? e.g.: Instead of <div>${foobar}</div> , I would like to use the syntax <div>{{foobar}}</div> . I can't seem to find any references in the Mako docs. 回答1: As of March 6, 2015, it's not currently possible . See the feature request to add configurable delimiters for Mako. 来源: https://stackoverflow.com/questions/28890953/how-to-change-the-mako-substitution-delimiter

How to change the mako substitution delimiter characters?

走远了吗. 提交于 2019-12-04 14:12:05
Is it possible to change the "delimiter tags" for expression substitution in the Python Mako templating library? If so, how? e.g.: Instead of <div>${foobar}</div> , I would like to use the syntax <div>{{foobar}}</div> . I can't seem to find any references in the Mako docs . As of March 6, 2015, it's not currently possible . See the feature request to add configurable delimiters for Mako. 来源: https://stackoverflow.com/questions/28890953/how-to-change-the-mako-substitution-delimiter-characters

Strip whitespace from Mako template output (Pylons)

柔情痞子 提交于 2019-12-03 14:12:00
I'm using Mako + Pylons and I've noticed a horrendous amount of whitespace in my HTML output. How would I go about getting rid of it? Reddit manage to do it. I'm not sure if there's a way to do it within Mako itself but you can always just do some post-rendering processing before you serve up the page. For example, say you have the following code that generates your horrendous whitespace: from mako import TemplateLookup template_lookup = TemplateLookup(directories=['.']) template = template_lookup.get_template("index.mako") whitespace_mess = template.render(somevar="no whitespace here") return

How do you debug Mako templates?

有些话、适合烂在心里 提交于 2019-12-03 03:02:59
问题 So far I've found it impossible to produce usable tracebacks when Mako templates aren't coded correctly. Is there any way to debug templates besides iterating for every line of code? 回答1: Mako actually provides a VERY nice way to track down errors in a template: from mako import exceptions try: template = lookup.get_template(uri) print template.render() except: print exceptions.html_error_template().render() 回答2: Looking at the Flask-Mako source, I found an undocumented configuration