Pylons ====== This tutorial assumes basic familiarity with Pylons. Beginners should read `Getting Started with Pylons`_. The tutorial was developed using Pylons 0.9.7rc4. .. _Getting Started with Pylons: http://www.pylonshq.com/docs/en/0.9.7/gettingstarted/ First, create an app using the standard approach. It doesn't really matter what options you use, although this tutorial assumes mako templates and that SQLAlchemy is enabled:: $ paster create --template=pylons myapp Enter template_engine (mako/genshi/jinja/etc: Template language) ['mako']: Enter sqlalchemy (True/False: Include SQLAlchemy 0.4 configuration) [False]: True To enable ToscaWidgets, edit ``myapp/config/middleware.py`` and add the following at the top:: import tw.api as twa And, after the line that says ``CUSTOM MIDDLEWARE HERE``, add:: app = twa.make_middleware(app, { 'toscawidgets.framework': 'pylons', 'toscawidgets.framework.default_view': 'mako', }) We'll now create a new controller to serve the test widget:: $ paster controller movie Inside the controller, we'll create the widget. Edit ``myapp/controllers/movie.py`` and add:: from tw.forms.samples import AddUserForm test_form = AddUserForm('mytest') In the same file, update the ``index`` method in ``MovieController`` to use a template:: def index(self): return render('/movie.mako') We now need to create this template. Create ``myapp/templates/movie.mako`` with the following content:: <%! from myapp.controllers.testwidget import test_form %> ToscaWidgets Tutorial

Welcome to the ToscaWidgets tutorial!

${test_form()|n} Finally, configure routing so the controller can be called. Edit ``myapp/config/routing.py`` and add (just after the line ``CUSTOM ROUTES HERE``):: map.connect('/movie', controller='movie') Start the app and load the ``/movie`` page; it should look like this: .. image:: test_form.png .. warning:: The configuration described here does not work well with cacheing done in the Pylons' :func:`render` function.In this scenario it is best to inject resources manually by calling :func:`tw.api.inject_resources` on the HTML string before cacheing it.