Request factory

class tangled.web.request.Request(environ, app, *args, **kwargs)[source]

Default request factory.

Every request has a reference to its application context (i.e.,

abort(status_code, *args, **kwargs)[source]

Abort the request by raising a WSGIHTTPException.

This is a convenience so resource modules don’t need to import exceptions from webob.exc.

get_setting(*args, **kwargs)[source]

Get an app setting.

Simply delegates to


Get helpers for this request.

Returns a Helpers instance; all the helpers added via will be accessible as methods of this instance.

make_url(path, query=None, fragment=None, *, _fully_qualified=True)[source]

Generate a URL.

path should be application-relative (that is, it should not include SCRIPT_NAME).

query can be a string, a dict, or a sequence. See make_query_string() for details.

If fragment is passed it will be quoted using urllib.parse.quote() with no “safe” characters (i.e., all special characters will be quoted).

on_finished(callback, *args, **kwargs)[source]

Add a finished callback.

Callbacks must have the signature (app, response). They can also take additional positional and keyword args–*args and **kwargs will be passed along to the callback.

Finished callbacks are always called regardless of whether an error occurred while processing the request. They are called just before the Tangled application returns to its caller.

All finished callbacks will be called. If any of them raises an exception, a RequestFinishedException will be raised and a “500 Internal Server Error” response will be returned in place of the original response.

Raising instances of webob.exc.WSGIHTTPException in finished callbacks is an error.

The response object can be inspected to see if an error occurred while processing the request. If the response is None, the request failed hard (i.e., there was an uncaught exception before the response could be created).

This can be used as a decorator in the simple case where the callback doesn’t take any additional args.


Get info for the resource associated with this request.


This can’t be safely accessed until after the resource has been found and set for this request.

resource_path(resource, urlvars=None, **kwargs)[source]

Generate a URL path (with SCRIPT_NAME) for a resource.

resource_url(resource, urlvars=None, **kwargs)[source]

Generate a URL for a resource.


Create the default response object for this request.

The response is initialized with attributes set via @config: status, location, and response_attrs.

If no status code was set via @config, we try our best to set it to something sane here based on content type and method.

If location is set but status isn’t, the response’s status is set to DEFAULT_REDIRECT_STATUS.

The location can also be set to one of the special values ‘REFERER’ or ‘CAME_FROM’. The former redirects back to the refering page. The latter redirects to whatever is set in the came_from request parameter.

TODO: Check origin of referer and came from.


See note in resource_config().


Get the content type to use for the response.

This retrieves the content types the resource is configured to handle then selects the best match for the requested content type. If the resource isn’t explicitly configured to handle any types or of there’s no best match, the default content type will be used.


This can’t be safely accessed until after the resource has been found and set for this request.

static_url(path, query=None, **kwargs)[source]

Generate a static URL from path.

path should always be an application-relative path like ‘/static/images/logo.png’. SCRIPT_NAME will be prepended by make_url().


Set multiple attributes on request.response.