-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Mapping code to a url
While trying to figure out what exactly some bit of code you're looking at does, or trying to test a bugfix, it's helpful to be able to visit pages that actually use the code in question.
First, let's take a look at how urls get mapped to controllers, as that will make the reverse process much easier to understand.
The first place to start is routing.py
. As the name suggests, this file contains the primary routing logic to decide what code should be called for each request. While Pylons has some documentation on the module, it's not terribly helpful; you'll probably find the routing section of the tutorial easier to understand.
There's some code in controllers/__init__.py
that handles the specifics of mapping controller
to an actual file, but what you need to know is this: do a case-insensitive search in that file for <controller name>Controller
and you'll find where it's imported from.
From there, you should be pretty much set - that class should be defined in a file in the controllers
directory, and the action
from routing.py
maps to a method. Now it's on to normal code execution and tracing.
The backward process is a bit more difficult, since there is no trivial way to find mappings from definitions back to callsites. sgrep
, git grep
, grep
, and ack
are your friends, and hopefully you'll eventually work your way back to routing.py
.