diff options
| author | Tom Christie | 2013-04-04 05:17:19 -0700 |
|---|---|---|
| committer | Tom Christie | 2013-04-04 05:17:19 -0700 |
| commit | 5b56639e7a26ba31ffe472b69408c427346df85b (patch) | |
| tree | 9159a68f99f84c1abf8b016dfcaedf99e251f91d /rest_framework | |
| parent | df30b345b1166d5bb50a9d880fbbff90201372a4 (diff) | |
| parent | 77ac2044294cb1dc40d715abd1bb63543beac95b (diff) | |
| download | django-rest-framework-5b56639e7a26ba31ffe472b69408c427346df85b.tar.bz2 | |
Merge pull request #777 from glic3rinu/master
Break long headers on the browsable API
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/templates/rest_framework/base.html | 2 | ||||
| -rw-r--r-- | rest_framework/templatetags/rest_framework.py | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/rest_framework/templates/rest_framework/base.html b/rest_framework/templates/rest_framework/base.html index 44633f5a..4410f285 100644 --- a/rest_framework/templates/rest_framework/base.html +++ b/rest_framework/templates/rest_framework/base.html @@ -115,7 +115,7 @@ </div> <div class="response-info"> <pre class="prettyprint"><div class="meta nocode"><b>HTTP {{ response.status_code }} {{ response.status_text }}</b>{% autoescape off %} -{% for key, val in response.items %}<b>{{ key }}:</b> <span class="lit">{{ val|urlize_quoted_links }}</span> +{% for key, val in response.items %}<b>{{ key }}:</b> <span class="lit">{{ val|break_long_headers|urlize_quoted_links }}</span> {% endfor %} </div>{{ content|urlize_quoted_links }}</pre>{% endautoescape %} </div> diff --git a/rest_framework/templatetags/rest_framework.py b/rest_framework/templatetags/rest_framework.py index 1d7a499f..c86b6456 100644 --- a/rest_framework/templatetags/rest_framework.py +++ b/rest_framework/templatetags/rest_framework.py @@ -260,3 +260,14 @@ def urlize_quoted_links(text, trim_url_limit=None, nofollow=True, autoescape=Tru elif autoescape: words[i] = escape(word) return ''.join(words) + + +@register.filter +def break_long_headers(header): + """ + Breaks headers longer than 160 characters (~page length) + when possible (are comma separated) + """ + if len(header) > 160 and ',' in header: + header = mark_safe('<br> ' + ', <br>'.join(header.split(','))) + return header |
