Resolve PUT and POST buttons in browsable API

This commit is contained in:
Tom Christie 2014-11-20 13:43:38 +00:00
parent 9c6bead8b6
commit 6ec96d0bac
2 changed files with 20 additions and 2 deletions

View File

@ -429,7 +429,10 @@ class HTMLFormRenderer(BaseRenderer):
style['base_template'] = self.base_template
style['renderer'] = self
if 'template' in style:
# This API needs to be finessed and finalized for 3.1
if 'template' in renderer_context:
template_name = renderer_context['template']
elif 'template' in style:
template_name = style['template']
else:
template_name = style['template_pack'].strip('/') + '/' + style['base_template']
@ -555,7 +558,14 @@ class BrowsableAPIRenderer(BaseRenderer):
if data is not None:
serializer.is_valid()
form_renderer = self.form_renderer_class()
return form_renderer.render(serializer.data, self.accepted_media_type, self.renderer_context)
return form_renderer.render(
serializer.data,
self.accepted_media_type,
dict(
self.renderer_context.items() +
[('template', 'rest_framework/api_form.html')]
)
)
def get_raw_data_form(self, data, view, method, request):
"""

View File

@ -0,0 +1,8 @@
{% load rest_framework %}
{% csrf_token %}
{% for field in form %}
{% if not field.read_only %}
{% render_field field style=style %}
{% endif %}
{% endfor %}
<!-- form.non_field_errors -->