mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Resolve PUT and POST buttons in browsable API
This commit is contained in:
parent
9c6bead8b6
commit
6ec96d0bac
|
@ -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):
|
||||
"""
|
||||
|
|
8
rest_framework/templates/rest_framework/api_form.html
Normal file
8
rest_framework/templates/rest_framework/api_form.html
Normal 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 -->
|
Loading…
Reference in New Issue
Block a user