From f15d2203d75b7a648d278bf3b2c9c0dce0e32877 Mon Sep 17 00:00:00 2001 From: Roland van Laar Date: Mon, 2 Mar 2015 15:43:21 +0100 Subject: [PATCH 1/2] 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) From d0ea6bfe0228a5b47abad8f5f79284d1f11c6b79 Mon Sep 17 00:00:00 2001 From: Roland van Laar Date: Mon, 2 Mar 2015 15:53:43 +0100 Subject: [PATCH 2/2] Add necessary import: json. --- rest_framework/utils/html.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rest_framework/utils/html.py b/rest_framework/utils/html.py index e825bdbeb..df08770f1 100644 --- a/rest_framework/utils/html.py +++ b/rest_framework/utils/html.py @@ -1,6 +1,7 @@ """ Helpers for dealing with HTML input. """ +import json import re from django.utils.datastructures import MultiValueDict