rest_framework.templatetags.rest_framework

Module Contents

register
class_re
highlight_code(parser, token)
class CodeNode(lang, code)

Bases:django.template.Node

style = emacs
render(self, context)
with_location(fields, location)
render_markdown(markdown_text)
get_pagination_html(pager)
render_form(serializer, template_pack=None)
render_field(field, style)
optional_login(request)

Include a login snippet if REST framework’s login view is in the URLconf.

optional_docs_login(request)

Include a login snippet if REST framework’s login view is in the URLconf.

optional_logout(request, user)

Include a logout snippet if REST framework’s logout view is in the URLconf.

add_query_param(request, key, val)

Add a query parameter to the current request url, and return the new url.

as_string(value)
as_list_of_strings(value)
add_class(value, css_class)

https://stackoverflow.com/questions/4124220/django-adding-css-classes-when-rendering-form-fields-in-a-template

Inserts classes into template variables that contain HTML tags, useful for modifying forms without needing to change the Form objects.

Usage:

{{ field.label_tag|add_class:”control-label” }}

In the case of REST Framework, the filter is used to add Bootstrap-specific classes to the forms.

format_value(value)
items(value)

Simple filter to return the items of the dict. Useful when the dict may have a key ‘items’ which is resolved first in Django tempalte dot-notation lookup. See issue #4931 Also see: https://stackoverflow.com/questions/15416662/django-template-loop-over-dictionary-items-with-items-as-key

data(value)

Simple filter to access data attribute of object, specifically coreapi.Document.

As per items filter above, allows accessing document.data when Document contains Link keyed-at “data”.

See issue #5395

Recursively find every link in a schema, even nested.

add_nested_class(value)
TRAILING_PUNCTUATION = ['.', ',', ':', ';', '.)', '"', "']", "'}", "'"]
WRAPPING_PUNCTUATION = [['(', ')'], ['<', '>'], ['[', ']'], ['&lt;', '&gt;'], ['"', '"'], ["'", "'"]]
word_split_re
simple_url_re
simple_url_2_re
simple_email_re
smart_urlquote_wrapper(matched_url)

Simple wrapper for smart_urlquote. ValueError(“Invalid IPv6 URL”) can be raised here, see issue #1386

Converts any URLs in text into clickable links.

Works on http://, https://, www. links, and also on links ending in one of the original seven gTLDs (.com, .edu, .gov, .int, .mil, .net, and .org). Links can have trailing punctuation (periods, commas, close-parens) and leading punctuation (opening parens) and it’ll still do the right thing.

If trim_url_limit is not None, the URLs in link text longer than this limit will truncated to trim_url_limit-3 characters and appended with an ellipsis.

If nofollow is True, the URLs in link text will get a rel=”nofollow” attribute.

If autoescape is True, the link text and URLs will get autoescaped.

break_long_headers(header)

Breaks headers longer than 160 characters (~page length) when possible (are comma separated)