私はdjangoフォームを持っています-
{{ field }}
これにより、次のHTMLが得られます。
<input id="id_producers" type="text" class="long-input" value="[Lawrence Bender]" />
value属性をクリーンアップする必要があります。そのために、次のテンプレートタグを作成しました。
{{ field|clean_list_string }}
def clean_list_string(field):
value = field.value()
if str(value).startswith('[') and str(value).endswith(']'):
value = ast.literal_eval(value)
if str(value)[1] == '(':
value = ', '.join('(' + ', '.join(i) + ')' for i in value)
else:
value = ', '.join(value)
return ??? (value)
返されるHTMLの値が変更されるように、正しいバインドされたメソッドを返すにはどうすればよいですか。
<input id="id_producers" type="text" class="long-input" value="Lawrence Bender" />