When I'm running Jinja2 in Google App Engine, I get useless debugging information. I gather this is because of this item in the FAQ:
My tracebacks look weird. What’s happening?
If the speedups module is not compiled and you are using a Python installation without ctypes (Python 2.4 without ctypes, Jython or Google’s AppEngine) Jinja2 is unable to provide correct debugging information and the traceback may be incomplete. There is currently no good workaround for Jython or the AppEngine as ctypes is unavailable there and it’s not possible to use the speedups extension.
While there is no 'good' workaround for this at the moment, is there any workaround so that the information printed when exceptions arise can be made more helpful?
Thank you for reading.
Brian
from_string . Jinja 2 provides a Template class that can be used to do the same, but with optional additional configuration. Jinja 1 performed automatic conversion of bytes in a given encoding into unicode objects.
Jinja is a web template engine for the Python programming language. It was created by Armin Ronacher and is licensed under a BSD License. Jinja is similar to the Django template engine but provides Python-like expressions while ensuring that the templates are evaluated in a sandbox.
You can get around this by adding _ctypes and gestalt to the development server's C module whitelist with monkeypatching.
To do so, put the following snippet at the top of your main.py:
import os if os.environ.get('SERVER_SOFTWARE', '').startswith('Dev'): # Enable ctypes for Jinja debugging from google.appengine.tools.dev_appserver import HardenedModulesHook HardenedModulesHook._WHITE_LIST_C_MODULES += ['_ctypes', 'gestalt']
You can also use this trick to enable other C modules, if you have similar local-only module needs. Do note that these modules still won't actually work once you deploy, so tread carefully.
On SDK 1.6.3 using python2.7 you need to change the above code to:
import os if os.environ.get('SERVER_SOFTWARE', '').startswith('Dev'): # Enable ctypes for Jinja debugging import sys from google.appengine.tools.dev_appserver import HardenedModulesHook assert isinstance(sys.meta_path[0], HardenedModulesHook) sys.meta_path[0]._white_list_c_modules += ['_ctypes', 'gestalt']
On SDK 1.8.6 for python 2.7, try this:
PRODUCTION_MODE = not os.environ.get( 'SERVER_SOFTWARE', 'Development').startswith('Development') if not PRODUCTION_MODE: from google.appengine.tools.devappserver2.python import sandbox sandbox._WHITE_LIST_C_MODULES += ['_ctypes', 'gestalt']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With