use plim in flask, bottle etc.
Hi,
I'm trying to get plim working with flask via flask-mako (http://pythonhosted.org//Flask-Mako/), but couldn't get it to work:
from flask import Flask
from flask.ext.mako import MakoTemplates
from plim import preprocessor
from flask.ext.mako import render_template
from mako.template import Template
app = Flask(__name__)
app.config['Mako_PREPROCESSOR'] = preprocessor
mako = MakoTemplates(app)
app.template_folder = 'templates'
temp = Template('a.plim', preprocessor=preprocessor)
@app.route('/')
def hello():
return temp.render()
if __name__ == '__main__':
app.run()
Could you take a look when you have the time and maybe add some docs for flask, bottle as well; plim seems really nice to use :)
Thanks a lot,
Hello! I apologise for a late response.
Unfortunatelly I've never used Flask and cannot provide you a working configuration example. I will get back to this ticket once I have spare time to answer it in full.
P.S. Contributions into documentation with regard to this subject are highly appreciated.
Thanks
I am currently toying around with this too and a basic working example is this app.py @hyao:
from flask import Flask
from flask.ext.mako import MakoTemplates, render_template
from plim import preprocessor
app = Flask(__name__)
mako = MakoTemplates(app)
app.config['MAKO_PREPROCESSOR'] = preprocessor
@app.route('/')
def hello():
return render_template('hello.html', name='mako')
if __name__ == "__main__":
app.run(debug=True)
and the template file templates/hello.html:
doctype html
html
head
title hello ${name}
body
p hello ${name}
What is missing is some nice integration ala pyjade where you basically add a line and then you are able to render ".jade" files using the default render_template of flask. I have no idea if something like that would be feasible though due to the reliance on jinja for rendering.
@rmoorman Thanks, your code snippet works.
Just added create a PR based on your code to the docs: https://github.com/avanov/Plim/pull/38
Btw, just found a tool emmet.io, it could save lots of typing for html writing.
Thanks,
Being able to render .plim files like pyjade does would be super as well! :)
Can be closed as #38 is merged.