Associate url’s path to view identifier / rql queries.

CubicWeb finds all registered URLPathEvaluators, orders them according to their priority attribute and calls their evaluate_path() method. The first that returns something and doesn’t raise a PathDontMatch exception wins.

Here is the default evaluator chain:

  1. cubicweb_web.views.urlpublishing.RawPathEvaluator handles unique url segments that match exactly one of the registered controller’s __regid__. Urls such as /view?, /edit?, /json? fall in that category;

  2. cubicweb_web.views.urlpublishing.EidPathEvaluator handles unique url segments that are eids (e.g. /1234);

  3. cubicweb_web.views.urlpublishing.URLRewriteEvaluator selects all urlrewriter components, sorts them according to their priority, call their rewrite() method, the first one that doesn’t raise a KeyError wins. This is where the cubicweb_web.views.urlrewrite and cubicweb_web.views.urlrewrite.SimpleReqRewriter comes into play;

  4. cubicweb_web.views.urlpublishing.RestPathEvaluator handles urls based on entity types and attributes : <etype>((/<attribute name>])?/<attribute value>)? This is why cwuser/carlos works;

  5. cubicweb_web.views.urlpublishing.ActionPathEvaluator handles any of the previous paths with an additional trailing “/<action>” segment, <action> being one of the registered actions’ __regid__.


Actionpath executes a query whose results is lost because of redirecting instead of direct traversal.

exception cubicweb_web.views.urlpublishing.PathDontMatch[source]#

exception used by url evaluators to notify they can’t evaluate a path

class cubicweb_web.views.urlpublishing.URLPublisherComponent(vreg, default_method='view')[source]#

Bases: cubicweb_web.view.Component

Associate url path to view identifier / rql queries, by applying a chain of urlpathevaluator components.

An evaluator is a URLPathEvaluator subclass with an .evaluate_path method taking the request object and the path to publish as argument. It will either return a publishing method identifier and an rql query on success or raise a PathDontMatch exception on failure. URL evaluators are called according to their priority attribute, with 0 as the greatest priority and greater values as lower priority. The first evaluator returning a result or raising something else than PathDontMatch will stop the handlers chain.

process(req, path)[source]#

Given a URL (essentially characterized by a path on the server, but additional information may be found in the request object), return a publishing method identifier (e.g. controller) and an optional result set.

  • req (cubicweb_web.request.CubicWebRequestBase) – the request object

  • path (str) – the path of the resource to publish. If empty, None or “/” “view” is used as the default path.

Return type

tuple(str, cubicweb.rset.ResultSet or None)


the publishing method identifier and an optional result set


NotFound – if no handler is able to decode the given path

class cubicweb_web.views.urlpublishing.URLPathEvaluator(urlpublisher)[source]#

Bases: cubicweb_web.view.Component

class cubicweb_web.views.urlpublishing.RawPathEvaluator(urlpublisher)[source]#

Bases: cubicweb_web.views.urlpublishing.URLPathEvaluator

handle path of the form:

class cubicweb_web.views.urlpublishing.EidPathEvaluator(urlpublisher)[source]#

Bases: cubicweb_web.views.urlpublishing.URLPathEvaluator

handle path with the form:

class cubicweb_web.views.urlpublishing.RestPathEvaluator(urlpublisher)[source]#

Bases: cubicweb_web.views.urlpublishing.URLPathEvaluator

handle path with the form:

<etype>[[/<attribute name>]/<attribute value>]*
class cubicweb_web.views.urlpublishing.URLRewriteEvaluator(urlpublisher)[source]#

Bases: cubicweb_web.views.urlpublishing.URLPathEvaluator

tries to find a rewrite rule to apply

URL rewrite rule definitions are stored in URLRewriter objects

class cubicweb_web.views.urlpublishing.ActionPathEvaluator(urlpublisher)[source]#

Bases: cubicweb_web.views.urlpublishing.URLPathEvaluator

handle path with the form:

<any evaluator path>/<action>