Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2360 (closed documentation: migrated)

Opened 10 years ago

Last modified 8 years ago

Documentation for app_globals unclear

Reported by: europe72 Owned by: mpedersen
Priority: normal Milestone: 2.1 docs
Component: Documentation Version: 2.1
Severity: minor Keywords:
Cc: europe72, toshio

Description

When serving an application via paste/HTTP app_globals appears not to be available without an import statement such as "from myapp.lib.app_globals import Globals." And then to access global variables etc. you need something similar to the following: Globals.foo. This is 1). contradictory to the inline documentation provided in app_globals.py and 2). contradictory to how paster shell works; In paster shell there is indeed a global obj named app_globals. And in shell app_globals.foo works.

Would be nice is app_globals was available right out of the gate and if it worked as described in in the inline docs (see below copy of docblock from app_globals.py)

"""Container for objects available throughout the life of the application.

One instance of Globals is created during application initialization and is available during requests via the 'app_globals' variable.

"""

Happy hunting

Change History

comment:1 Changed 10 years ago by jorge.vargas

  • Milestone set to 2.1 docs

comment:2 Changed 9 years ago by toshio

  • Cc toshio added

I think that what you're meant to do is something like this:

from tg import app_globals

app_globals.foo

This matches the inline documentation but it isn't clear from the inline documentation or anywhere in the TG2 docs that this is what is meant.

 http://turbogears.org/2.1/docs/main/explorequickstart.html#globals-py

has a reference to app_globals that might fit. Perhaps adding an example to the inline documentation would help:

globals.py
~~~~~~~~~~~~

Every app may have some global settings or information that's shared across all requests, but it's very possible that you may want to run two TG2 apps in the same process, or even two instances of the same app in a single process.  If so, ``app_globals.py`` provides a simple mechanism for storing application specific globals which don't clobber the globals on other instances of the same app.

.. code-block:: python

    class Globals(object):
        """Container for objects available throughout the life of the application.

        One instance of Globals is created during application initialization and
        is available during requests via the 'app_globals' variable.  For example,
        set a foo global in the __init__() of this class::

            def __init__(self):
                self.foo = 'Test global!'

        Then, in your application code you can access foo like this::

            from tg import app_globals

            @expose('mytemplate')
            def test(self):
                return dict(msg=app_globals.foo)

        """

        def __init__(self):
            """Do nothing, by default."""
            pass

The ``app_globals`` and ``helpers`` stuff is pre-loaded into the tg
environment for you by the config system.   Which is what we will
look into next.

comment:3 Changed 8 years ago by pedersen

  • Status changed from new to closed
  • Resolution set to migrated
Note: See TracTickets for help on using tickets.