For example, when installing on Unix-like systems as a normal user, you normally need to prefix commands with sudo to run the installation with root privileges. If you experience problems with the TurboGears download or installation, please write to the mailing list where the community can help you. When you have found a solution for your problem and you think it may be useful for others as well, you can open a documentation ticket.
Make sure, you have the Python setuptools installed. If not:. Install virtualenv from the Cheeseshop:. Now, every time you open a new terminal session to work with the new environment, you need to activate it by running the source command given above. The --no-site-packages option to virtualenv specifies that in your environment there is no access to the modules installed in the system-wide Python site-packages directorie s.
This is normally recommended, since this prevents problems due to dependency interferences with packages installed there. But if you need access to some packages there, e. BaseController classes and the expose decorator are the basis of TurboGears controllers. The expose decorator declares that your method should be exposed to the web , and provides you with the ability to say how the results of the controller should be rendered.
RootController is the required standard name for the RootController class of a TurboGears application and it should inherit from the BaseController class. In TurboGears 2 the web site is represented by a tree of controller objects and their methods, and a TurboGears website always grows out from the RootController class.
The index method is the start point of any TurboGears controller class. Each of the URLs. As you can see from the examples, the response to a given URL is determined by the method it maps to. The expose seen before each controller method directs TurboGears controllers to make the method accessible through the web server.
There is much more to expose. It will be our access to TurboGears sophisticated rendering features that we will explore shortly. As shown above, controller methods return the data of your website. So far, we have returned this data as literal strings. You could produce a whole site by returning only strings containing raw HTML from your controller methods, but it would be difficult to maintain, since Python code and HTML code would not be cleanly separated. To enable a cleaner solution, data from your TurboGears controller can be returned as strings, or as a dictionary.
With expose , a dictionary can be passed from the controller to a template which fills in its placeholder keys with the dictionary values and then returns the filled template output to the browser. A simple template file called sample could be made like this:.
There are only two steps necessary to install TurboGears, if you already have Python installed. Download the tgsetup. We strongly suggest that you also refer to the system-specific installation instructions for details.
The recommended Python version to use with TurboGears 1. Python 2. There are some detailed installation instructions for different platforms and setups, starting with instructions for installing Python to platform-specific configuration issues. If you need to choose a database option, SQLite is an easy-to-use database to get started with, which works with plain files or in-memory databases.
0コメント