| Name |
Space |
Section |
Version |
Status |
Reviewed |
Author(s) |
| Adding Controllers without restarting (during run-time) |
Pylons Cookbook |
Controllers |
1.0 |
Draft |
False |
Ben Bangert |
Introduction
Sometimes, its necessary for an application to add controllers without restarting the application. This requires telling Routes (which scans the controller directory for valid routes) to re-scan the directory.
Adding the controller
The controller may be added from the command line with the paster command (recommended as that also creates the test harness file), or any other means of creating the controller file.
Telling Routes about the new controller
For Routes to become aware of new controllers present in the controller directory, Routes needs to have an internal flag toggled indicating that it should rescan the directory.
Example
1
2
3
4 | from routes import request_config
mapper = request_config().mapper
mapper._created_regs = False
|
On the next request, Routes will rescan the controllers directory, and routes that use the ':controller' dynamic part path will be able to match the new controller.