Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rest_framework/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ class HTMLFormRenderer(BaseRenderer):
'base_template': 'input.html',
'input_type': 'time'
},
serializers.FileField: {
'base_template': 'file_input.html',
'input_type': 'file'
},
serializers.BooleanField: {
'base_template': 'checkbox.html'
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends "rest_framework/horizontal/input.html" %}

{% block input %}
<input name="{{ field.name }}" type="{{ style.input_type }}" {% if style.placeholder %}placeholder="{{ style.placeholder }}"{% endif %} {% if field.value %}value="{{ field.value }}"{% endif %}>
{% endblock %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've avoided block overriding at all costs so far.

Either we can:

  • Have form-control be something that's passed to all other input fields except file in the context.
  • Not write form_control if style.input_type == file.
  • Go with what you have here, but be explicit rather than using block overriding.

Additionally we need to make the same fix for the vertical and inline styles.

2 changes: 2 additions & 0 deletions rest_framework/templates/rest_framework/horizontal/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<label class="col-sm-2 control-label {% if style.hide_label %}sr-only{% endif %}">{{ field.label }}</label>
{% endif %}
<div class="col-sm-10">
{% block input %}
<input name="{{ field.name }}" class="form-control" type="{{ style.input_type }}" {% if style.placeholder %}placeholder="{{ style.placeholder }}"{% endif %} {% if field.value %}value="{{ field.value }}"{% endif %}>
{% endblock %}
{% if field.errors %}
{% for error in field.errors %}<span class="help-block">{{ error }}</span>{% endfor %}
{% endif %}
Expand Down