Pyramid framework tips : Beaker session factory settings

In Pyramid framework there is default session factory as shown below:

# default session factory, not secure, use pyramid beaker add-on
from pyramid.session import UnencryptedCookieSessionFactoryConfig
session_factory = UnencryptedCookieSessionFactoryConfig("mysession")

It is unencrypted, details  can be found in Pyramid docs.

There is pyramid_beaker add-on package as alternative. Beaker is a library for caching and sessions for use with web applications and stand-alone Python scripts and applications. For pyramid_beaker settings:

Install pyramid_beaker add-on package with easy_install:

$ easy_install pyramid_beaker

In development.ini and production.ini:

[app:main]
...
pyramid.includes = pyramid_debugtoolbar
                                   pyramid_tm
                                   pyramid_beaker                   

# pyramid_beaker add-on settings
session.type = file
session.data_dir = %(here)s/data/sessions/data
session.lock_dir = %(here)s/data/sessions/lock
session.key = customerskey
session.secret = customerssecret
session.cookie_on_exception = true
...

in Pyramid Application in __init__.py:

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    # default session factory, not secure, use pyramid beaker
    # session_factory = UnencryptedCookieSessionFactoryConfig("mysession")

    # pyramid_beaker add-on
    session_factory = session_factory_from_settings(settings)

    config = Configurator(
        settings=settings,
        session_factory=session_factory
    )
  ...

Pyramid framework tips : Mako Templates settings

mako templates pyramid framework

In Pyramid framework you can use the mako templates.

In development.ini and production.ini:

[app:main]
...
# mako template settings
mako.directories = YOUR_PROJECT_NAME:templates
...

It is better to save your mako files with *.html if you use html editors or Eclipse / Aptana.
For *.html you must add pyramid mako renderer factory in Pyramid Application in __init__.py:

def main(global_config, **settings):
  """ This function returns a Pyramid WSGI application.
  """
  ...
  # mako settings for file extension .html
  config.add_renderer(".html", "pyramid.mako_templating.renderer_factory")

If you are not adding mako templating renderer factory, you get this error:
ValueError: No such renderer factory .html

Debug Pyramid projects through eclipse (aptana studio)

aptana studio 3 pyramid framework debug

In my previous post i wrote pyramid framework settings in eclipse (aptana studio).

How can i debug pyramid projects through eclipse (aptana studio)?

When you give  “–reload” parameter in your project run configuration in arguments tab, eclipse will not debug your pyramid application.

development.ini –reload  => start without debugging

1 – delete “–reload” parameter in your project run configuration in arguments tab

development.ini  => start with debugging.

2 – set your debug points in your classes.

3 – click your debug configuration menu in eclipse toolbar -> debug button.

* debug icon credit