From f15d2203d75b7a648d278bf3b2c9c0dce0e32877 Mon Sep 17 00:00:00 2001 From: Roland van Laar Date: Mon, 2 Mar 2015 15:43:21 +0100 Subject: [PATCH] Personal fix for issue: #2566 When an HTML form is used to submit data to DRF this function parse_html_list is called. This functions can't parse a list of strings. To work around this, post the data as a valid JSON list: ```["example string 1", "test string 2"]``` This list is parsed as JSON and returned. Thus allowing a formdata with a list to be submitted. --- rest_framework/utils/html.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rest_framework/utils/html.py b/rest_framework/utils/html.py index d773952dc..e825bdbeb 100644 --- a/rest_framework/utils/html.py +++ b/rest_framework/utils/html.py @@ -49,6 +49,12 @@ def parse_html_list(dictionary, prefix=''): for field, value in dictionary.items(): match = regex.match(field) if not match: + try: + normalized_value = json.loads(value) + except ValueError: + continue + if field == prefix and isinstance(normalized_value, list): + return normalized_value continue index, key = match.groups() index = int(index)