Templating in restish

3 views
Skip to first unread message

Niels Pardon

unread,
Jul 12, 2010, 6:31:08 AM7/12/10
to ish.io
Hey guys!

I'm currently trying to make templating work with restish. I have to
admit that I'm quite new to Python at all. So maybe it's just
something simple I overlook. Would be great if you could help me.

- I've used the paster template to create the default project
structure.
- I've uncommented the lines for the Mako renderer in lib/
templating.py (and installed the Mako renderer via easy_install
Mako :-).
- I've added an @templating.page('capabilities.json') to one of my
methods of a resource.
- I've tried to start the server with "paster serve development.ini".

What I get is something that looks like a stack trace with the
following final two lines:

@templating.page('capabilities.json')
NameError: name 'templating' is not defined

Would be great if you could give me a hint on how to fix this. Please
tell me if you need any further information.

Regards,

Niels

Matt Goodall

unread,
Jul 12, 2010, 8:51:05 AM7/12/10
to is...@googlegroups.com


Hi Niels,

I think you're just missing an import. Try adding "from restish import
templating" to the top of the module that uses the @templating.page
decorator.

However, unless you have a strange use case, I'm not sure a Mako
template is the ideal way of rendering JSON. I would probably render
the result using a json module.

import json
from restish import http, resource

class ExampleResource(resource.Resource):
@resource.GET(accept='json')
def json(self, request):
obj = {...}
return http.ok([], json.dumps(obj))

Hope that helps.

- Matt

Niels Pardon

unread,
Jul 15, 2010, 3:36:55 PM7/15/10
to ish.io
Hi Matt!

Thanks for your answer! You're right! Using the JSON module makes more
sense. I first thought a template might be a good idea but it
wasn't :-)

I thought the import would have already been done in the lib/
templating.py which is imported in the wsgiapp.py. So I had already
tried adding the import to the resource/root.py but it didn't work out
as expected. I got an error from Mako: "NameError: Undefined"

But as already said I'm using the JSON module now. So no need for help
here.

Regards,

Niels
Reply all
Reply to author
Forward
0 new messages