Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ it easier to reuse code for common HTTP operations and to structure projects
so other developers with knowledge of the framework can quickly build and
maintain the application.

<div class="well see-also">Web frameworks are a concept implemented by <a href="/django.html">Django</a>, <a href="/flask.html">Flask</a>, <a href="/bottle.html">Bottle</a>, <a href="/pyramid.html">Pyramid</a>, <a href="/morepath.html">Morepath</a> and <a href="/other-web-frameworks.html">several other libraries</a>. Learn how the parts fit together in the <a href="/web-development.html">web development</a> chapter or view <a href="/table-of-contents.html">all topics</a>.</div>
<div class="well see-also">Web frameworks are a concept implemented by <a href="/django.html">Django</a>, <a href="/flask.html">Flask</a>, <a href="/bottle.html">Bottle</a>, <a href="/pyramid.html">Pyramid</a>, <a href="/morepath.html">Morepath</a>, <a href="/turbogears.html">TurboGears</a> and <a href="/other-web-frameworks.html">several other libraries</a>. Learn how the parts fit together in the <a href="/web-development.html">web development</a> chapter or view <a href="/table-of-contents.html">all topics</a>.</div>


### Common web framework functionality
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ frameworks that have their own dedicated pages:

* [Pyramid](/pyramid.html)

* [TurboGears](/turbogears.html)

* [Bottle](/bottle.html)

* [Falcon](/falcon.html)
Expand All @@ -28,14 +30,6 @@ frameworks that have their own dedicated pages:
* [Sanic](/sanic.html)


## TurboGears
[TurboGears](http://www.turbogears.org), born as a full stack layer on top
of Pylons, is now a standalone web framework that can act both as a full
stack library (like Django) or as a micro framework.

<a href="http://www.turbogears.org/" style="border: none;"><img src="/img/logos/turbogears.jpg" width="100%" alt="TurboGears logo." class="technical-diagram" style="border-radius: 5px;"></a>


## web.py
[web.py](http://webpy.org/) is a Python web framework designed for simplicity
in building web applications.
Expand Down
168 changes: 168 additions & 0 deletions content/pages/04-web-development/64-turbogears.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
title: TurboGears
category: page
slug: turbogears
sortorder: 0405
toc: False
sidebartitle: TurboGears
meta: TurboGears is a batteries included web framework that can act both as a full stack or microframework solution, with MongoDB as a first citizen storage.

# TurboGears
[TurboGears](http://www.turbogears.org), born as a full stack layer on top
of Pylons, is now a standalone [WSGI](/wsgi-servers.html) web framework
that can act both as a full stack framework (like [Django](/django.html))
or as a micro framework (like [Flask](/flask.html))

<a href="http://www.turbogears.org/" style="border: none;">
<img src="/img/logos/turbogears.jpg" width="100%" alt="TurboGears logo." class="technical-diagram" style="border-radius: 5px;">
</a>

Originally inspired by RubyOnRails it's based on MVC
where the controller dispatches the request to a set of actions
exposed from the controller itself.

TurboGears, in its full stack mode, provides all the features
you would require during development of a web application:

* [Identification and Authentication](http://turbogears.readthedocs.io/en/latest/turbogears/authentication.html)
* [Authorization](http://turbogears.readthedocs.io/en/latest/turbogears/authorization.html)
* [Autogenerated Admin and CRUD](http://turbogears.readthedocs.io/en/latest/cookbook/admin.html)
* [Sessions](http://turbogears.readthedocs.io/en/latest/turbogears/session.html)
* [Caching](http://turbogears.readthedocs.io/en/latest/turbogears/caching.html)
* [Schema Migrations](http://turbogears.readthedocs.io/en/latest/turbogears/migrations.html)
* [Master/Slave Database Queries Balancing](http://turbogears.readthedocs.io/en/latest/cookbook/master-slave.html)
* Request Bound Transactions
* Interactive Debugger
* Builtin Profiling
* Pluggable Applications

It's also one of the few web frameworks officially supporting
MongoDB as one of the primary storage backends, including
support into the TurboGears Admin to autogenerate CRUDs
from MongoDB models.

While TurboGears has always been a full stack framework
with same scope of projects like Django, it differentiates
from other frameworks due the its philosophy on two major
parts of a web framework: *Templating* and *Routing*

## Templating

While TurboGears provides support for multiple template
engines, the primary one has always been a fully
validated XML template engine.

Currently TurboGears ships with the ``Kajiki`` template engine,
which was developed within the project itself, but in the past
it relied on the Genshi and Kid template engines which were
mostly syntax compatible with Kajiki.

Historically validated xml template engines has always been
slower than text template engines, but the Kajiki project
was able to create a very fast template engine that usually
renders faster than Mako or Django Template while
still retaining all the expected features.

The fact that it relies on a validated XML engine provides
some benefits compared to plain text engines like Django
Template, Jinja2 and Mako:

### Automatic Escaping

It automatically escapes content rendered into the
template, thus making easier to avoid XSS and injection
security issues:

```
<div>${value}</div>
```

with ``value='<script>alert("hello")</script>'``
will render as

```
<div>&lt;script&gt;alert(&quot;hello&quot;)&lt;/script&gt;</div>;
```

thus preventing any form of injection from user provided content.

### Automatic Internationalization

The template engine parses the provided template document
and recognises the nodes that contain static text.

As the engine is able to distinguish text from markup it's
able to flag the text for translation.

Content like ``<div>Hello World</div>`` would get automatically
translated if a translation for ``"Hello World"`` is provided,
without having to wrap text in ``gettext`` calls.

### Compatibility with WYSIWYG Editors

As the template engine syntax is purely valid XHTML
the template itself can be opened with WYSIWYG editors
and as far as they don't strip unknown attributes
the template can be edited and saved back from those editors.

## Routing

Most web frameworks have been relying on regular expressions
to declare routing, through decorators or through a routing map.

TurboGears supports regular expressions through the ``tgext.routes``
extension, but the preferred way of routing is through the
``Object Dispatch`` system.

In Object Dispatch a root controller object is traversed while
resolving the URL. Each part of the url path is mapped to a property
of the controller (Which might point to a sub controller) until
a final collable action is encountered.

This leads to a very natural mapping between URLs and the code
serving them, allowing people with minimal knowledge of a project
to jump in and quickly find actions in charge of serving a specific page.

In Object Dispatch an URL like ``/users/new?name=MyName``
would be served by a hierarchy of objects like:

```
class UsersController(TGController):
@expose()
def new(self, name=None):
return 'Hi, %s' % name

class RootController(TGController):
users = UsersController()
```

It's easy to see how ``/users/new`` actually resolves
to ``RootController.users.new`` and all options provided
to the URL are passed to the action serving the respose
as arguments.

## TurboGears Resources

* [TurboGears Introduction Video](https://www.youtube.com/watch?v=-QqQVBzU4lM&t=16s)
An overview of TurboGears2 features presented at the PyConWeb

* [TurboGears Documentation](http://turbogears.readthedocs.io/en/latest/)
The official TurboGears documentation

* [Microframework Mode Tutorial](http://turbogears.readthedocs.io/en/latest/turbogears/minimal/index.html)
The official tutorial that focuses on starting TurboGears in microframework
mode and leads to developement of a single file web application

* [FullStack Tutorial](http://turbogears.readthedocs.io/en/latest/turbogears/wiki20.html)
The Wiki in 20 minutes tutorial that showcases how to create a fully
functional wiki application with TurboGears in full stack mode.

* [The CogBin](http://www.turbogears.org/cogbin.html)
The CogBin is a list of the most common pluggable applications for
TurboGears, it enlists ready made pieces you can plug into your
web application to provide features like Facebook Login,
Comments, Registration and so on...

* [React in Pure Python](https://medium.com/@__amol__/es2015-and-react-in-pure-python-environment-b326dc15012c)
An article showcasing how to create web applications relying on React
without the need to have NodeJS installed at all. The article
uses TurboGears as the web framework to develop the example application.
18 changes: 18 additions & 0 deletions theme/templates/choices/turbogears.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<h3>What do you want to learn next?</h3>
<div class="row">
<div class="c4">
<div class="well select-next">
{% include "choices/buttons/deployment.html" %}
</div>
</div>
<div class="c4">
<div class="well select-next">
{% include "choices/buttons/cascading-style-sheets.html" %}
</div>
</div>
<div class="c4">
<div class="well select-next">
{% include "choices/buttons/other-web-frameworks.html" %}
</div>
</div>
</div>