Provides common classes and functions most users will want access to.
Returns the Routes RequestConfig object.
To get the Routes RequestConfig:
>>> from routes import *
>>> config = request_config()
The following attributes must be set on the config object every request:
Set to the WSGI environ for automatic prefix support if the webapp is underneath a ‘SCRIPT_NAME’
Setting the environ will use information in environ to try and populate the host/protocol/mapper_dict options if you’ve already set a mapper.
Using your own requst local
If you have your own request local object that you’d like to use instead of the default thread local provided by Routes, you can configure Routes to use it:
from routes import request_config()
config = request_config()
if hasattr(config, 'using_request_local'):
config.request_local = YourLocalCallable
config = request_config()
Once you have configured request_config, its advisable you retrieve it again to get the object you wanted. The variable you assign to request_local is assumed to be a callable that will get the local config object you wish.
This example tests for the presence of the ‘using_request_local’ attribute which will be present if you haven’t assigned it yet. This way you can avoid repeat assignments of the request specific callable.
Should you want the original object, perhaps to change the callable its using or stop this behavior, call request_config(original=True).
RequestConfig thread-local singleton
The Routes RequestConfig object is a thread-local singleton that should be initialized by the web framework that is utilizing Routes.