Category: Turbo Gears

  • Deployment

    To switch over from a development environment to a full-fledged production environment, application needs to be deployed on a real web server. Depending upon what you have, there are different options available to deploy a TurboGears web application. Apache with mod_wsgi The mod_wsgi is an Apache module developed by Graham Dumpleton. It allows WSGI programs…

  • Pluggable Applications

    If your extension needs to expose models and controllers, you probably want to have a look at the Pluggable Applications, which are meant to create reusable Turbogears applications that can be plugged inside other applications to extend their features. Use the following gearbox command to create a pluggable application −gearbox quickstart-pluggable plugtest These pluggable applications can…

  • Writing Extensions

    TurboGears extensions are identified by tgext.* package. A Gearbox toolkit provides tgext command to create a sample extension. For example − Other optional parameters for this command are − This will create a tgext.myextension directory, which has a simple sample extension inside. Run the setup.py inside the directory −Python setup.py install The _init_.py file inside tgext/myextension folder contains − Brief version…

  • Hooks

    There are three ways in TurboGears to plug behaviors inside the existing applications. Here in this chapter, we will discuss how to use hooks inside an existing application. Hooks Hooks are events registered in the application’s configuration file app_cfg.py. Any controller is then hooked to these events by event decorators. The following hooks are defined in…

  • Scaffolding

    Gearbox toolkit contains scaffold command, which is very useful to quickly create new components of TurboGears application. An application generated by quickstart command of gearbox has a skeleton template in the model folder (model.py.template), a templates folder (template.html.template) and a controllers folder (controller.py.template). These ‘.template’ files are used as basis for creating new scaffolds for…

  • Pagination

    TurboGears provides a convenient decorator called paginate() to divide output in the pages. This decorator is combined with the expose() decorator. The @Paginate() decorator takes the dictionary object of query result as argument. In addition, the number of records per page are decided by value of items_per_page attribute. Ensure that you import paginate function from…

  • CRUD Operations

    The following session methods perform CRUD Operations − You can apply filter to the retrieved record set by using a filter attribute. For instance, in order to retrieve records with city = ’Hyderabad’ in students table, use the following statement − We shall now see how to interact with the models through controller URLs. First…

  • Flash Messages

    TurboGears provides a very convenient messaging system for notifying information to user in a non-obtrusive way. TGFlash class in tg module provides support for flashing messages that are stored in a plain cookie. This class supports fetching flash messages on server side as well as client side through JavaScript. The render() method of TGFlash class, when used…

  • Validation

    A good Forms widget library should have an input validation feature. For example, the user should be forced to enter data in a mandatory field, or verify if an email field contains a valid email, without resorting to any other programmatic means (like JavaScript function) for validation. Early versions of ToscaWidgets Forms Library used to…

  • JSON Rendering

    The @expose() decorator by default renders html content. However, this can be set to json content type. TurboGears supports json rendering through tg.jsonify.JSONEncoder (**kwargs) class. To render json data simply pass json as content type to expose decorator.@expose(‘json’) def jsondata(self, **kwargs): return dict(hello = ‘World’) If ‘/jsondata’ URL is entered in browser, it will respond by showing − jsonp Rendering…