TODO: documentation =================== Miscelaneous notes abotu things to be documented. Unordered list of topics to be documented ----------------------------------------- - routing - common regular expressions examples - sessions - basic usage & configuration - using multiple sessions in the same request - using different backends - using flashes - updating session arguments (max_age etc) - purging db sessions - i18n (increment existing tutorial) - basic usage & configuration - loading locale/timezone automatically for each request - formatting date/time/datetime - formatting currency - using i18n in templates - jinja2 & mako - basic usage & configuration - setting global filters and variables (using config or factory) - auth - basic usage & configuration - setting up 'own auth' - making user available automatically on each request - purging tokens - config - configuration conventions ("namespaced" configuration for webapp2_extras modules) - tricks - configuration in a separate file - routes in a separate file - reduce verbosity when defining routes (R = webapp2.Route) Common errors ------------- - "TypeError: 'unicode' object is not callable": one possible reason is that the ``RequestHandler`` returned a string. If the handler returns anything, it **must** be a :class:`webapp2.Response` object. Or it must not return anything and write to the response instead using ``self.response.write()``. Secret keys ----------- Add a note about how to generate strong session secret keys:: $ openssl genrsa -out ${PWD}/private_rsa_key.pem 2048 Jinja2 factory -------------- To create Jinja2 with custom filters and global variables:: from webapp2_extras import jinja2 def jinja2_factory(app): j = jinja2.Jinja2(app) j.environment.filters.update({ 'my_filter': my_filter, }) j.environment.globals.update({ 'my_global': my_global, }) return j # When you need jinja, get it passing the factory. j = jinja2.get_jinja2(factory=jinja2_factory) Debugging Jinja2 ---------------- http://stackoverflow.com/questions/3086091/debug-jinja2-in-google-app-engine/3694434#3694434 Configuration notes ------------------- Notice that configuration is set primarily in the application. See: http://webapp-improved.appspot.com/guide/app.html#config By convention, modules that are configurable in webapp2 use the module name as key, to avoid name clashes. Their configuration is then set in a nested dict. So, e.g., i18n, jinja2 and sessions are configured like this:: config = {} config['webapp2_extras.i18n'] = { 'default_locale': ..., } config['webapp2_extras.jinja2'] = { 'template_path': ..., } config['webapp2_extras.sessions'] = { 'secret_key': ..., } app = webapp2.WSGIApplication(..., config=config) You only need to set the configuration keys that differ from the default ones. For convenience, configurable modules have a 'default_config' variable just for the purpose of documenting the default values, e.g.: http://webapp-improved.appspot.com/api/extras.i18n.html#webapp2_extras.i18n.default_config Cookies, quoting & unicode -------------------------- http://groups.google.com/group/webapp2/msg/985092351378c43e http://stackoverflow.com/questions/6839922/unicodedecodeerror-is-raised-when-getting-a-cookie-in-google-app-engine Marketplace integration ----------------------- .. code-block:: xml Tipfy A simple application for testing the marketplace. Tipfy https://app-id.appspot.com/a/${DOMAIN_NAME}/ https://app-id.appspot.com https://apps-apis.google.com/a/feeds/user/#readonly Users can be selected to gain special permissions to access or modify content.