mako

RDBMS & OOP-friendly Python web app framework?

Suppose your boss told you to choose a Python web application framework, and you would be wedded to it for at least the next 3 years. What would you recommend? Ground rules: Python: Yes, required. (Ruby+ not an option for reasons irrelevant. Case closed.) Custom/Hybrid Setups: Sure... if they are defensible on technical grounds. Up...

How do you debug Mako templates?

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? Edit: Per the comments, it seems switching to Jinja2 might be the best solution. ...

Trimming Mako output

I really like the Mako templating system that's used in Pylons and a couple other Python frameworks, and my only complaint is how much WS leaks through even a simple inheritance scheme. Is there anyway to accomplish below, without creating such huge WS gaps... or packing my code in like I started to do with base.mako? Otherwise to get ...

Matching a pair of comments in HTML using regular expressions

I have a mako template that looks something like this: % if staff: <!-- begin staff --> ... <!-- end staff --> % endif That way if I pass the staff variable as being True, those comments should appear. I'm trying to test this by using a regular expression that looks like this: re.search('<!-- begin staff -->.*<!-- end st...

Syntax Highlight for Mako in Eclipse or TextMate?

Hi, does anyone know of a syntax highlight for mako templates for eclipse or for textmate? I know that there is a .mako syntax highlighter for the default text editor in ubuntu. Thanks a lot. Claudio. ...

How do I call template defs with names only known at runtime in the Python template language Mako?

I am trying to find a way of calling def templates determined by the data available in the context. Edit: A simpler instance of the same question. It is possible to emit the value of an object in the context: # in python ctx = Context(buffer, website='stackoverflow.com') # in mako <%def name="body()"> I visit ${website} all the time...

Formatting with mako

Anyone know how to format the length of a string with Mako? The equivalent of print "%20s%10s" % ("string 1", "string 2")? ...

Form Initialization with ToscaWidgets

Question: How do I prefill a CheckBoxTable from ToscaWidgets with values. Background: I've looked everywhere and I can't seem to figure out how to initialize a particular form field with ToscaWidgets. Most form fields seem to respond just fine to initialization, like if I create a form with a single TextField in it when I render the ...

FormEncode, pylons, and mako example

I'm working in pylons with mako, and I'd like to create forms and validations with FormEncode for several parts of my application. I can't seem to find any good examples of the whole process. My question is twofold: Technical FancyValidators and Schemas - Their relationship and syntax Pylons controllers and mako templates - how ...

How do I link relative to a Pylons application root?

In Pylons I have a mako template linking to /static/resource.css. How do I automatically link to /pylons/static/resource.css when I decide to map the application to a subdirectory on my web server? ...

What is the fastest template system for Python?

Jinja2 and Mako are both apparently pretty fast. How do these compare to (the less featured but probably good enough for what I'm doing) string.Template ? ...

Should I use Mako for Templating?

I've been considering a templating solution, although my choices are between Mako and Genshi. I find templating in Genshi a bit ugly, so I'm shifting more towards Mako. I've gone to wonder: what is so good about the fact that Mako allows embedded Python code? How is it convenient for the average joe? Wouldn't templating JUST suffice wi...

Mark string as safe in Mako

I'm using Pylons with Mako templates and I want to avoid typing this all the time: ${ h.some_function_that_outputs_html() | n } I want to somehow mark the function, or a variable as safe (you can do that in Django) so I don't have to pipe-en all the time. Any ideas? ...

Good way to pass variables for common elements to Mako templates?

I'm using Mako's inheritance features to factor out common page elements, like a header and footer, into a "base.mako" template. Page-specific controllers use their own templates, which inherit base.mako. base.mako needs a set of variables -- for example, the name of the logged-on user goes in the header for all pages. However, it's ...

turbogears request/user object in templates and request context

Hi all, I am currently making the switch from Django to Turbogears 2.1 and am running into some problems that I could not find the answers to in the Turbogears docs. If tg developers read this, let me tell you that one of the best features Django has over TG is its documentation! 1) How do I access the request (user?) object within a m...

Turbogears, mako form displaying as plain text

Hi 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.templat...

Mako templates use old version until I manually update template files

I periodically get this problem where all of a sudden mako is using old versions of templates, and it's not until I manually go and update the template files that they'll use the current version. I'm using ./manage.py runserver I think it's usually after I update using source control, but it's intermittent, and I can't reliably reprod...

How to properly escape output (for XHTML) in mako?

Despite offering a nice way to escape output using filters, none of them do the right thing. Taking the string: x=u"&\u0092" The filters do the following: x Turns the & into an entity but not the \u0092 (valid XML but not XHTML) h Exactly the same u Escapes both, but obviously uses url escaping ent...

How can I access the current URI in python's mako templating system?

I'd like to submit the form to the current URI, like this: <form action="${CURRENT_URI}" method="post"> <input type="text" name="email" /> </form> from within a mako template. But I am not sure what variable holds the current uri information. Thanks. ...

How to track state when iterating in Python's Mako Templates

I want to loop over a list and print the elements seperated by ',', with no trailing comma. I can't just ', '.join(headings) because of the formating and escaping. But the following obviously leaves me with a trailing comma. % for x in headings: <a href='#${x|u}'>${x}</a>, \ % endfor Or more generally: When iterating over something ...