mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 00:04:16 +03:00
Docs for AdminRenderer
This commit is contained in:
parent
4c1597efe0
commit
5c1d6a9200
|
@ -153,23 +153,13 @@ You can use `StaticHTMLRenderer` either to return regular HTML pages using REST
|
||||||
|
|
||||||
See also: `TemplateHTMLRenderer`
|
See also: `TemplateHTMLRenderer`
|
||||||
|
|
||||||
## HTMLFormRenderer
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
**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.
|
|
||||||
|
|
||||||
**.media_type**: `text/html`
|
|
||||||
|
|
||||||
**.format**: `'.form'`
|
|
||||||
|
|
||||||
**.charset**: `utf-8`
|
|
||||||
|
|
||||||
**.template**: `'rest_framework/form.html'`
|
|
||||||
|
|
||||||
## BrowsableAPIRenderer
|
## BrowsableAPIRenderer
|
||||||
|
|
||||||
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.
|
Renders data into HTML for the Browsable API:
|
||||||
|
|
||||||
|
![The BrowsableAPIRenderer](../img/quickstart.png)
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
**.media_type**: `text/html`
|
**.media_type**: `text/html`
|
||||||
|
|
||||||
|
@ -187,6 +177,38 @@ By default the response content will be rendered with the highest priority rende
|
||||||
def get_default_renderer(self, view):
|
def get_default_renderer(self, view):
|
||||||
return JSONRenderer()
|
return JSONRenderer()
|
||||||
|
|
||||||
|
## AdminRenderer
|
||||||
|
|
||||||
|
Renders data into HTML for an admin-like display:
|
||||||
|
|
||||||
|
![The AdminRender view](../img/admin.png)
|
||||||
|
|
||||||
|
This renderer is suitable for CRUD-style web APIs that should also present a user-friendly interface for managing the data.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
**.media_type**: `text/html`
|
||||||
|
|
||||||
|
**.format**: `'.admin'`
|
||||||
|
|
||||||
|
**.charset**: `utf-8`
|
||||||
|
|
||||||
|
**.template**: `'rest_framework/admin.html'`
|
||||||
|
|
||||||
|
## HTMLFormRenderer
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
**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.
|
||||||
|
|
||||||
|
**.media_type**: `text/html`
|
||||||
|
|
||||||
|
**.format**: `'.form'`
|
||||||
|
|
||||||
|
**.charset**: `utf-8`
|
||||||
|
|
||||||
|
**.template**: `'rest_framework/form.html'`
|
||||||
|
|
||||||
## MultiPartRenderer
|
## MultiPartRenderer
|
||||||
|
|
||||||
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].
|
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].
|
||||||
|
|
BIN
docs/img/admin.png
Normal file
BIN
docs/img/admin.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 55 KiB |
|
@ -705,6 +705,7 @@ class AdminRenderer(BrowsableAPIRenderer):
|
||||||
# Creation and deletion should use redirects in the admin style.
|
# Creation and deletion should use redirects in the admin style.
|
||||||
if (response.status_code == status.HTTP_201_CREATED) and ('Location' in response):
|
if (response.status_code == status.HTTP_201_CREATED) and ('Location' in response):
|
||||||
response.status_code = status.HTTP_302_FOUND
|
response.status_code = status.HTTP_302_FOUND
|
||||||
|
response['Location'] = request.build_absolute_uri()
|
||||||
ret = ''
|
ret = ''
|
||||||
|
|
||||||
if response.status_code == status.HTTP_204_NO_CONTENT:
|
if response.status_code == status.HTTP_204_NO_CONTENT:
|
||||||
|
|
|
@ -112,8 +112,8 @@ def add_class(value, css_class):
|
||||||
def format_value(value):
|
def format_value(value):
|
||||||
if getattr(value, 'is_hyperlink', False):
|
if getattr(value, 'is_hyperlink', False):
|
||||||
return mark_safe('<a href=%s>%s</a>' % (value, escape(value.name)))
|
return mark_safe('<a href=%s>%s</a>' % (value, escape(value.name)))
|
||||||
if isinstance(value, (int, float, decimal.Decimal, bool, type(None))):
|
if value in (True, False, None):
|
||||||
return mark_safe('<code>%s</code>' % escape(value))
|
return mark_safe('<code>%s</code>' % {True: 'true', False: 'false', None: 'null'}[value])
|
||||||
elif isinstance(value, list):
|
elif isinstance(value, list):
|
||||||
if any([isinstance(item, (list, dict)) for item in value]):
|
if any([isinstance(item, (list, dict)) for item in value]):
|
||||||
template = loader.get_template('rest_framework/admin/list_value.html')
|
template = loader.get_template('rest_framework/admin/list_value.html')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user