cubicweb.pyramid.url_redirection
Contents
cubicweb.pyramid.url_redirection
#
Url redirection using pyramid#
This module allow to define redirection rules used by pyramid before route selection.
Each rule has to be added with add_rewriting_rule method in a pyramid includeme function to be used.
Example of usage :
def includeme(config):
config.add_rewriting_rule(r'<a regex>', callback_method)
The callback_method takes three arguments:
a pyramid request ;
the url that has to be matched by the rule ;
a dictionnary containing all the named subgroups of the regex match.
It must return a string corresponding to the new url.
- cubicweb.pyramid.url_redirection.includeme(config)[source]#
Add add_redirection_rule pyramid directive and url_redirection_tween pyramid tween handler to the pyramid configuration.
- cubicweb.pyramid.url_redirection.add_redirection_rule(config, rule, callback_method)[source]#
Declare a pyramid directive allowing to add a redirection rule. Each rewriting rule can then be added in the includeme at the end of the file by using config.add_redirection_rule(rule, callback_method. :param config: pyramid configuration, used by pyramid. :param rule: a regex used to match uri. :param callback_method: a method which return the redirected uri.