Exemplo n.º 1
0
 def add_url_rule(self,
                  url_rule,
                  view_func,
                  name,
                  default=False,
                  **options):
     rule = UrlRule(url_rule, view_func, name, **options)
     # Protect against multiple routes on a single name. If we are attempting to add another
     # route, set the value to None. Then when url_for is called, we can check and raise an error
     # if resolving is ambiguous.
     if name in self._view_functions.keys():
         self._view_functions[name] = None
     else:
         self._view_functions[name] = rule
     self._routes.append(rule)
Exemplo n.º 2
0
    def add_url_rule(self, url_rule, view_func, name, options=None):
        '''This method adds a URL rule for routing purposes. The
        provided name can be different from the view function name if
        desired. The provided name is what is used in url_for to build
        a URL.

        The route decorator provides the same functionality.
        '''
        rule = UrlRule(url_rule, view_func, name, options)
        if name in self._view_functions.keys():
            # TODO: Raise exception for ambiguous views during registration
            log.warning('Cannot add url rule "%s" with name "%s". There is '
                        'already a view with that name' % (url_rule, name))
            self._view_functions[name] = None
        else:
            log.debug('Adding url rule "%s" named "%s" pointing to function '
                      '"%s"' % (url_rule, name, view_func.__name__))
            self._view_functions[name] = rule
        self._routes.append(rule)