Miscellaneous view helpers¶
Helper functions for view handlers.
All items in this module can be imported directly from coaster.views
.
-
coaster.views.misc.
get_current_url
()[source]¶ Return the current URL including the query string as a relative path. If the app uses subdomains, return an absolute path
-
coaster.views.misc.
get_next_url
(referrer=False, external=False, session=False, default=<object object>)[source]¶ Get the next URL to redirect to. Don’t return external URLs unless explicitly asked for. This is to protect the site from being an unwitting redirector to external URLs. Subdomains are okay, however.
This function looks for a
next
parameter in the request or in the session (depending on whether parametersession
is True). If nonext
is present, it checks the referrer (if enabled), and finally returns either the provided default (which can be any value includingNone
) or the script root (typically/
).
-
coaster.views.misc.
jsonp
(*args, **kw)[source]¶ Returns a JSON response with a callback wrapper, if asked for. Consider using CORS instead, as JSONP makes the client app insecure. See the
cors()
decorator.
-
coaster.views.misc.
endpoint_for
(url, method=None, return_rule=False, follow_redirects=True)[source]¶ Given an absolute URL, retrieve the matching endpoint name (or rule) and view arguments. Requires a current request context to determine runtime environment.
Parameters: Returns: Tuple of endpoint name or URL rule or None, view arguments