Skip to content

Commit 5c1d6a9

Browse files
committed
Docs for AdminRenderer
1 parent 4c1597e commit 5c1d6a9

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

docs/api-guide/renderers.md

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,23 +153,13 @@ You can use `StaticHTMLRenderer` either to return regular HTML pages using REST
153153

154154
See also: `TemplateHTMLRenderer`
155155

156-
## HTMLFormRenderer
157-
158-
Renders data returned by a serializer into an HTML form. The output of this renderer does not include the enclosing `<form>` tags or an submit actions, as you'll probably need those to include the desired method and URL. Also note that the `HTMLFormRenderer` does not yet support including field error messages.
159-
160-
**Note**: The `HTMLFormRenderer` class is intended for internal use with the browsable API. It should not be considered a fully documented or stable API. The template used by the `HTMLFormRenderer` class, and the context submitted to it **may be subject to change**. If you need to use this renderer class it is advised that you either make a local copy of the class and templates, or follow the release note on REST framework upgrades closely.
161-
162-
**.media_type**: `text/html`
163-
164-
**.format**: `'.form'`
165-
166-
**.charset**: `utf-8`
156+
## BrowsableAPIRenderer
167157

168-
**.template**: `'rest_framework/form.html'`
158+
Renders data into HTML for the Browsable API:
169159

170-
## BrowsableAPIRenderer
160+
![The BrowsableAPIRenderer](../img/quickstart.png)
171161

172-
Renders data into HTML for the Browsable API. This renderer will determine which other renderer would have been given highest priority, and use that to display an API style response within the HTML page.
162+
This renderer will determine which other renderer would have been given highest priority, and use that to display an API style response within the HTML page.
173163

174164
**.media_type**: `text/html`
175165

@@ -187,6 +177,38 @@ By default the response content will be rendered with the highest priority rende
187177
def get_default_renderer(self, view):
188178
return JSONRenderer()
189179

180+
## AdminRenderer
181+
182+
Renders data into HTML for an admin-like display:
183+
184+
![The AdminRender view](../img/admin.png)
185+
186+
This renderer is suitable for CRUD-style web APIs that should also present a user-friendly interface for managing the data.
187+
188+
Note that views that have nested or list serializers for their input won't work well with the `AdminRenderer`, as the HTML forms are unable to properly support them.
189+
190+
**.media_type**: `text/html`
191+
192+
**.format**: `'.admin'`
193+
194+
**.charset**: `utf-8`
195+
196+
**.template**: `'rest_framework/admin.html'`
197+
198+
## HTMLFormRenderer
199+
200+
Renders data returned by a serializer into an HTML form. The output of this renderer does not include the enclosing `<form>` tags or an submit actions, as you'll probably need those to include the desired method and URL. Also note that the `HTMLFormRenderer` does not yet support including field error messages.
201+
202+
**Note**: The `HTMLFormRenderer` class is intended for internal use with the browsable API and admin interface. It should not be considered a fully documented or stable API. The template used by the `HTMLFormRenderer` class, and the context submitted to it **may be subject to change**. If you need to use this renderer class it is advised that you either make a local copy of the class and templates, or follow the release note on REST framework upgrades closely.
203+
204+
**.media_type**: `text/html`
205+
206+
**.format**: `'.form'`
207+
208+
**.charset**: `utf-8`
209+
210+
**.template**: `'rest_framework/form.html'`
211+
190212
## MultiPartRenderer
191213

192214
This renderer is used for rendering HTML multipart form data. **It is not suitable as a response renderer**, but is instead used for creating test requests, using REST framework's [test client and test request factory][testing].

docs/img/admin.png

54.6 KB
Loading

rest_framework/renderers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ def render(self, data, accepted_media_type=None, renderer_context=None):
705705
# Creation and deletion should use redirects in the admin style.
706706
if (response.status_code == status.HTTP_201_CREATED) and ('Location' in response):
707707
response.status_code = status.HTTP_302_FOUND
708+
response['Location'] = request.build_absolute_uri()
708709
ret = ''
709710

710711
if response.status_code == status.HTTP_204_NO_CONTENT:

rest_framework/templatetags/rest_framework.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ def add_class(value, css_class):
112112
def format_value(value):
113113
if getattr(value, 'is_hyperlink', False):
114114
return mark_safe('<a href=%s>%s</a>' % (value, escape(value.name)))
115-
if isinstance(value, (int, float, decimal.Decimal, bool, type(None))):
116-
return mark_safe('<code>%s</code>' % escape(value))
115+
if value in (True, False, None):
116+
return mark_safe('<code>%s</code>' % {True: 'true', False: 'false', None: 'null'}[value])
117117
elif isinstance(value, list):
118118
if any([isinstance(item, (list, dict)) for item in value]):
119119
template = loader.get_template('rest_framework/admin/list_value.html')

0 commit comments

Comments
 (0)