TurboGears Interview Questions & Answers

TurboGears Interview Questions

Getting prepared for TurboGears job interview? Do not panic, we will guide you how and what to answer in your interview. If you are preparing for TurboGears interview then go through Wisdomjobs TurboGears interview questions and answers page. TurboGears is a Python written application framework. It is released in 2005. Some of its features are- a powerful ORM, horizontal data partitioning, and support multi data exchange formats. It is used less in market but has high demand. It includes components like CherryPy, MochiKit, SQLObject, Genshi. Setup is very simple and has less number of dependencies. It is used in creating simple to complex applications. Please have a look at our TurboGears job interview questions and answers page to win your interview.


TurboGears Interview Questions And Answers

TurboGears Interview Questions
    1. Question 1. What Is Turbogears?

      Answer :

      TurboGears is a rapid development “front-to_back” web meta-framework. Its aim is to simplify and speed up the development of modern web applications written in the Python programming language.

    2. Question 2. How Is Turbogears Licensed? Can I Use It For Commercial Applications?

      Answer :

      TurboGears itself is licensed under the MIT license. Its different parts may be licensed differently. Please read the details on the license page.

      In general, all licenses allow commercial usage and even closed-source distribution of your application if you include a copy of the resp. license, but if in doubt, please consult your lawyer.

    3. Question 3. How Does Turbogears Compare To Ruby On Rails/django/pylons/etc.? Which Framework Should I Choose For My New Project?

      Answer :

      This is an ever popular topic on the mailing list. See,

      for example, these threads:

      • TurboGears vs Django (older) (2006-07-29)
      • TurboGears vs JSP vs PHP vs Ruby on Rails vs Webware (2006-08-15)
      • Who are the core TurboGears developers (2006-11-14)
      • Sharing between TurboGears/Django/Pylons/etc. (2006-12_02)
      • TurboGears vs Django (2006-12-05)

    4. Question 4. What Books Are Available For Learning Turbogears?

      Answer :

      The “official” TurboGears book is Rapid Web Applications with TurboGears by Mark Ramm et al.

    5. Question 5. When Can We Expect Python 2.5 Support?

      Answer :

      TurboGears supports Python 2.5 as of version 1.0.2.

    6. Question 6. When Can We Expect Python 2.6 Support?

      Answer :

      TurboGears officially supports Python 2.6 as of version 1.1.

    7. Question 7. How Can I Do Non-root Installations?how Can I Install Turbogears On A Unix-like System Without Root User Privileges?

      Answer :

      An easy and quick way is to use the virtualenv program to create a separate, clean Python environment and install TurboGears in this environment. The basic steps are:

      1. install virtualenv with easy_install virtualenv.
      2. Run virtualenv
      3. source /bin/activate
      4. Download tgsetup.py and run python tgsetup.py.
      5. Install additional eggs, like nose, pysqlite, SQLObject, SQLAlchemy, etc. with easy_install

      is the name of a directory that virtualenv should create. It will contain the new Python environment. Everytime you want to work with this environment, you need to carry out step 3. from above, so that the library modules and scripts from the environment are used.

    8. Question 8. Why Do I Get The Log Messages Twice?

      Answer :

      This is normal. The TurboGears application server, Cherrypy 2.x, runs two processes when in development mode and it’s set to autoreload. Each process outputs logging messages and that is why they appear twice. This does not happen in production mode and also doesn’t happen in newer (i.e. CP3) CherryPy versions (which TurboGears does not use yet), which involved a rewrite of the reloading mechanism.

    9. Question 9. What Causes "'stream' Object Has No Attribute 'tag'"?

      Answer :

      This is most probably caused by mixing Genshi and ToscaWidgets incorrectly.

      In the beginning, there was Kid and “traditional” widgets. Traditional widgets returned an ElementTree object, which the Kid engine converted into HTML. In Genshi, you can use traditional widgets, but you must use the "ET()" function to explicitly convert them to HTML. (If you get "<script elementat ASDFASDF>" in your output, that is a sign that you are handing a traditional widget back to Genshi, and NOT wrapping it in ET().)

      ToscaWidgets, on the other hand, return HTML natively. If you wrap a ToscaWidget reference in ET(), you will get a stack trace saying "'Stream' objecthas no attribute 'tag'".

      Note that these issues do not exist any more in TurboGears 1.1 and 1.5, they do all the necessary wrapping and converting for you. TurboGears 1.5 even allows Genshi templates in TurboGears widgets and will convert between the Kid and Genshi templating systems under the hood.

    10. Question 10. Why Do I Sometimes Get 500 Internal Errors After My App Has Been Idle?

      Answer :

      Are you using a MySQL database? If so, this is probably the MySQL time out. Because CherryPy is a long running process it doesn’t make a new connection on every page load. After a period of inactivity the MySQL server will timeout the connection. This causes an error the next time the application attempts to use the connection.

      One solution some people use is to set up a cron job that every so often wgets a page from the application that will cause a database query. There is also apparently a MySQL wait_timeout setting that can be adjusted to stop the connection from timing out.

    11. Question 11. Why Do My Ajax-enabled Widgets Stop Working After Some Minutes?

      Answer :

      This might be due to the fact that you have enabled identity and the session has timed out and the AJAX-calls from your widget (e.g. loadJSONDoc) encounter a 401 (“Unauthorized”) or 500 (“Internal Server Error”) error.

      A simple method to handle this would be to wrap the loadJSONDoc call and always add a errback callback function that catches this error:

      function ljd_errhandler(result) {
          if (result instanceof XMLHttpRequestError &&
              (result.number == 401 || result.number == 500) {
              /* handle error here, for example simply display an error message */

      function do_loadjsondoc(url, cb_func) {
          d = loadJSONDoc(url);
          d.addCallbacks(cb_func, ljd_erhandler);
          return d;

    12. Question 12. Why Does Turbogears 1.0 Still Use Cherrypy 2.x Instead Of Cherrypy 3?

      Answer :

      When TurboGears was created, CP3 didn’t exist and there where major changes between CP2 and CP3. Therefore the breaking changes required to support CP3 in have been made only in TG 1.5.

    13. Question 13. Which Alternative Template Engines Can I Use With Turbogears?

      Answer :

      In principle, you can use any templating language that provides a Buffet plugin interface, either directly or through a separate template engine pluginpackage. Template engines, that have been successfully used with TurboGears, include Genshi, Cheetah and Jinja. For general information how to use non-standard template engines with TurboGears, see Using Alternate Templating Engines.

      If you are using widgets, you need Kid to render the widgets, but you can still use a different template engine for your page templates. With ToscaWidget you can use any Buffet-compliant template engine for your widgets.

    14. Question 14. How Do I Deploy My Configuration And A Default Database?

      Answer :

      From TurboGears version 1.0.4b3 onwards it is easy to include a default configuration file in your application’s egg file, which then will be found by the standard start script automatically. You just have to uncomment a section in your project’s setup.py file, which is appropriatly commented. 

      While, in principle, one could also include a default database in the egg, this would only make sense for single-file databases, like those used by SQLite, but then again, one wouldn’t normally want to write to files contained in an egg.

      One solution is to provide a custom tg-admin command for your application, that asks the user for the database connection parameters and then initializes the database using the tg-admin sql create command followed by some custom code to fill the the dadabase with some bootstrap data.

    15. Question 15. How Can I Find The Filesystem Locations For My Project?

      Answer :

      Use the pkg_resources module which comes with setuptools

      For example, You can get the full path to the templates directory inside the wiki20 package by:

      from pkg_resources import resource_filename
      resource_filename('wiki20', 'templates')

      You can then easily move up an down in the filesystem by using the functions form the standard os.path module.

      Please bear in mind, when you have installed your application as an egg, there is no “project directory” per se, in fact, the files of your application may not even reside directly in the filesystem but in a ZIP archive. You can build an egg that contains additiional data file alongside your application’s package directory. See the setuptools documentation for more information.

    16. Question 16. How Can I Use Special Characters In My Urls?

      Answer :

      You can’t because method names have to conform to the rules for Python identifiers. But you can work around this by handling URL dispatching yourself in an exposed default method of your controller, ex: setattr(class, irregular, method) to effectively alias the page.

    17. Question 17. How Do I Change The Name Of A Project?

      Answer :

      To change the name of a project called “foo” created by tg-admin quickstart, you have to manually go through all the files of the project and replace all occurences of “foo” with “matrix”, where “matrix” is the new name of the project. If you are under Linux/Mac, you can automate this tedious work with this shell snippet:

      find . -name "*" |
          while read f; do
              sed -e 's#foo#matrix#g' < "$f" > /tmp/x
              mv /tmp/x "$f"

    18. Question 18. How Can I Output Html Passed By The Controller In My Kid Templates?

      Answer :

      Use ${XML(mytemplatevar)} or refactor by defining and using a kid template function, for example:

      <a py:def="link(url, text)" href='${url}'>${text}</a>

      Then in your template you use:

      ${link('http://foo.com/', 'Foo.com')}

      Which will render to this output:

      <a href='http://foo.com/'>Foo.com</a>

    19. Question 19. How Can I Organize My Templates Hierarchically?

      Answer :

      templates are looked up by the template engines via the normal Python module package mechanisms and the templates directory is therefore a Python package. Subdirectories have to be sub-packages as well and you can achieve that by placing an __init__.py file in them. The__init__.py can contain Python code, but an empty file will do just as well.

    20. Question 20. How To I Specify An Alternate Template To Use In My Controller Method?

      Answer :

      Put tg_template set to the name of the template you want to use into the dictionary you return from your controller method


      def index(self, **kw):
          d = dict(message='Hello World!')
          if some_condition:
              d['tg_template'] = '.templates.other'
          return d

    21. Question 21. How Do I Pre-fill (some) Fields When I Display A Widgets-based Form?

      Answer :

      You provide a dictionary to the value parameter when you display the widget in the template. The dictionary must contain the the field names as keys and their preset value as values. You pass both the widget form object and the values dictionary to the template from your controller method.


      # widgets.py
      myform = TableForm(
          fields = [
      # controllers.py
      from widgets import myform

      class MyController(controllers.controller):
          def showform(sefl, **kw):
              form_values = dict(
                  name = "Joe Doe",
                  email = "joe@doe.com"
              return dict(form=myform, form_values=form_values)
      <!-- form_template.kid -->

    22. Question 22. How Do I Validate Two Forms On The Same Page?

      Answer :

      Just set the action attribute of each form to a different value making them submit to two different controller methods.

      You can then use a @validate decorator with a different form argument on each method.

    23. Question 23. How Can I Write A Widget Which Displays An Image?

      Answer :

      That’s easy. Just include an image tag in the template of the widget:

      class ImageWidget(widgets.Widget):

      template = '<img xmlns:py="http://purl.org/kid/ns#" src="${value}" />'

      and provide the image URL when you display the widget:


      If you want to serve a dynamically generated image, you have to provide a controller method for this, and use the URL to this controller method as the value for the widget.

Popular Interview Questions

All Interview Questions

All Practice Tests

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

TurboGears Tutorial