Cannot use webapp2 Mako api

28 views
Skip to first unread message

Sunanda Samaddar

unread,
Jan 3, 2020, 10:02:22 AM1/3/20
to Google App Engine
Hi, I'm trying to use Mako with `webapp2_extras`, but I get this error everytime.
File "/Users/sunandosamaddar/google_drive/py/webapp2_apps/hellowebapp2/main.py", line 5, in <module>

   
from webapp2_extras import mako
 
File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/lib/webapp2-2.3/webapp2_extras/mako.py", line 15, in <module>
   
from mako import lookup
ImportError: No module named mako



main.py
```
#import cgi
#from google.appengine.api import users
import webapp2
from webapp2_extras import mako

mako.default_config = {'template_path': 'server/views'}

class BaseHandler(webapp2.RequestHandler):
def get(self):
@webapp2.cached_property
def mako(self):
# Returns a Mako renderer cached in the app registry.
return mako.get_mako(factory=mako.Mako(app=self.app, config=None), registry='webapp2_extras.mako.Mako', app=self.app)

def render_response(self, _template, **context):
# Renders a template and writes the result to the response.
rv = self.mako.render_template(_template, **context)
self.response.write(rv)


class HomeHandler(BaseHandler):
def get(self):
self.render_response('home.html', **context)


app = webapp2.WSGIApplication([('/', HomeHandler)], debug=True)
```

George (Cloud Platform Support)

unread,
Jan 3, 2020, 10:51:44 AM1/3/20
to Google App Engine
 You must add the mako package to your application directory for App Engine, as documented on the "Mako" page

This discussion group is oriented more towards general opinions, trends, and issues of general nature touching App Engine and Cloud SQL. For coding and programming architecture, as well as setting up Mako, you may be better served in dedicated forums such as stackoverflow, where experienced programmers are within reach and ready to help.
Reply all
Reply to author
Forward
0 new messages