Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
285 lines (200 sloc) 7.01 KB

Overview provides a common web application stub.

This includes a base web application layout, authentication integration, application model handling, view helpers and commonly needed UI widgets and AJAX helpers.


Application egg

Create your application egg and make it depend on You must depend your application as well to your prefered repoze.what plugin, i.e. repoze.what.plugins.ini which is used in example below.

Include the package in the configure.zcml of your application egg to make sure everything needed to run the framework is available.

<configure xmlns="">
    <include package="" />


Assuming Paster for WSGI deployment and buildout for the application setup, your (self contained) buildout configuration might look like this.

parts = instance
eggs-directory = ${buildout:directory}/eggs
find-links =
develop = .

recipe = repoze.recipe.egg:scripts
eggs =

Authentication and Authorization Configuration

Configure repoze.who and repoze.what by providing the corresponding configuration files.

We configure repoze.who to use HTTP basic auth via a htaccess file. A Plugin that fits our needs for form authentication is shipped with the package.

This is what our who.ini looks like.

use =
login_form_qs = loginform.__do_login
rememberer_name = auth_tkt

use = repoze.who.plugins.auth_tkt:make_plugin
secret = secret
cookie_name = __ac__
secure = False
include_ip = False

use = repoze.who.plugins.htpasswd:make_plugin
filename = %(here)s/etc/htpasswd
check_fn = repoze.who.plugins.htpasswd:crypt_check

request_classifier = repoze.who.classifiers:default_request_classifier
challenge_decider = repoze.who.classifiers:default_challenge_decider
remote_user_key = REMOTE_USER

plugins =

plugins = htpasswd

plugins = loginform

Create repoze.what configuration, defining plugins to use recognizing permissions and groups.

The file what.ini looks like this for using the repoze.what.plugins.ini adapters.

use = repoze.what.plugins.ini:INIGroupAdapter
filename = %(here)s/etc/repositories.ini

use = repoze.what.plugins.ini:INIPermissionsAdapter
filename = %(here)s/etc/permissions.ini

group_adapters = ini_group
permission_adapters = ini_permission

Read the documentation of repoze.what.plugins.ini for information about group and permission configuration via INI files.

Configure the WSGI pipeline

Here we use Paster to server our application.

We have to provide a configuration which ties all things together.

Create a file like yourapplication.ini which looks similar to this.

debug = true

use = egg:Paste#http
host =
port = 8080

use = egg:yourapplication#app
reload_templates = true
filter-with = what

use = egg:repoze.what.plugins.config#config
config_file = %(here)s/what.ini
who_config_file = %(here)s/who.ini

pipeline =

Provide the application

Provide the entry point yourapplication#app defined in the configuration above in your This entry point returns a WSGI app.

>>> setup(
...     #...
...     entry_points="""\
...         [paste.app_factory]
...         app =
...     """
...     #...
... )

yourapplication/ looks like this.

>>> from repoze.bfg.configuration import Configurator
>>> from yourapplication.model import get_root

>>> def app(global_config, **settings):
...     """ This function returns a WSGI application.
...     """
...     zcml_file = settings.get('configure_zcml', 'configure.zcml')
...     config = Configurator(root_factory=get_root, settings=settings)
...     config.begin()
...     config.load_zcml(zcml_file)
...     config.end()
...     return config.make_wsgi_app()

Provide the application model

The imported get_root function above is responsible to return the application model root node. Create a file which looks like.

>>> from import BaseNode

>>> class Root(BaseNode):
...     """Your application root Node.
...     """
...     title = "YourApplication"

>>> root = Root()

>>> def get_root(environ):
...     return root

See documentation of package zodict for more info about Nodes and section "Application model" for how it is used in

Provide a view for your root node

Now we have to provide a tile. Name it content and register it for the root node in order to render it.

See documentation of package bda.bfg.tile for more info about tiles and section "Reserved Tiles" which describe the application layout view hooks for your model.

Create a package named browser in you application egg. Define the root content tile in of browser package.

>>> from bda.bfg.tile import registerTile
>>> from import ProtectedContentTile
>>> from yourapplication.model import Root

>>> registerTile('content',
...              'yourapplication:browser/templates/',
...              interface=Root,
...              class_=ProtectedContentTile,
...              permission='login',
...              strict=False)

Also create a page template named at the indicated location.

  Root content

Now add the following line to your applications configure.zcml to scan the available views.

<scan package=".browser" />

Test the setup

Now the base application setup is done. Test your setup by

- running buildout

- and starting the WSGI pipline like
  ``./bin/paster serve yourapplication.ini``

You should be able now to browse the application at localhost:8080.





  • Initial work [rnix]
Jump to Line
Something went wrong with that request. Please try again.