This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Cave men often hunted by following animal trails through the woods. They could also follow trails to important natural resources; the very first human migrations may have been along the trails that migratory animal herds created when visiting natural salt deposits.

In the same tradition, the Trails product, which provides the Python package megrok.trails, allows Grok web site developers to define the URLs that web users can travel in order to visit the objects that roam their site.

If you need to report bugs or want to request features, please visit the project’s Launchpad site at:

Trails creates both the traversers which make URLs work in the forward direction (so that users can visit them and see the right objects), and also registers the adapters necessary for URLs to be generated (meaning that Grok can ask “at which URL does this object live?” and receive back an answer).

Trails look something like this when in use:

class MyTrails(megrok.trails.TrailHead):
    trails = [
        Trail('/person/:id', Person),
        Trail('/account/:username', Account),

The above example makes a URL like:

traverse to the object created by calling Person(id=3096), while a user visiting the URL:

will find the object created by calling Account(username=dcr). In each case, the colon-prefixed URL elements in the Trail become keyword arguments passed to the class (or other callable) given as the second argument to the Trail(). Each URL element that is not prefixed with a colon must be matched literally by the corresponding element in the submitted URL.

A TrailHead performs traversal for the object which you name as its grok.context(), so you do not have to define a traverse() method or create a grok.Traverser for that context yourself. When the remaining URL components fail to match any of the Trail patterns that start from a TrailHead, an error is raised that should return a 404 Not Found to the user (unless, of course, there is only a single URL component left and it names a view). If, instead, one of the URL patterns is matched, then the object named in the second argument of the Trail is instantiated with the colon-prefixed wildcard URL components provided as keyword parameters, as outlined above.

Once the trail has been matched and resolved to an object, Trails is done processing, and normal Grok traversal then takes over again to process any remaining URL components, or to look for a default view for the object if the end of the URL has been reached. So, in the above example, the developer would need to have provided normal grok.View classes for the Person and Account objects in order for the user to see them rendered in a browser. This means that Trails is not comparable to something like Rails Routes or Python Routes, because those products impose their own methods for choosing the view that gets placed atop an object. Trails, by contrast, leaves the normal Grok rules in place for how a view is selected and placed atop your object; it merely attempts to make object traversal itself cleaner and easier to maintain in an application where objects and containers do not literally exist in an object database like the ZODB.

Note that Trails stops, satisfied, once any Trail has been completed, and returns control to Grok. You cannot, therefore, have two working trails where one is a prefix of the other; the second Trail shown here will never be used:

trails = [
    Trail('/person/:id', Person),
    Trail('/person/:id/:acct', BankAccount), # will never be used!

Remember that Trails also registers adapters that tell Grok where each kind of object lives, so that if you, for example, are rendering a page full of Person objects as part of a search result, then you can call view.url(person) on each of them and Trails will construct URLs for them that are built like:

application_url + '/person/%s' %

If your trail had said something more ambitious, like:

Trail('/town/:name/:state', Town)

then the URL of any particular town would be formed by computing:

application_url + '/town/%s/%s' % (, town.state)

and might look like /town/Springfield/MA. Note that this means that Trails makes two assumptions about every class that you name as the second argument to a Trail: first, that it can safely be called with keyword arguments that look like the colon-prefixed wildcards that form the URL pattern; and, second, that any live object of that type will have attributes with those same two names which it can look up to form a URL for the object.

Please visit our project page (the link is near the top of this README) if you have any suggestions, bug reports, or questions about Trails. Enjoy!

Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
megrok.trails-1.0.tar.gz (10.3 kB) Copy SHA256 Checksum SHA256 Source Jul 17, 2008

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting