admin管理员组

文章数量:1352277

<input type="hidden" name="allowed-extensions" value="jpg,jpeg,png" />

I need to convert HTML post input field values or CSV values in a form to a Python list when the form is posted to Django, like in the above scenarios. Kindly let me know. Thank you

<input type="hidden" name="allowed-extensions" value="jpg,jpeg,png" />

I need to convert HTML post input field values or CSV values in a form to a Python list when the form is posted to Django, like in the above scenarios. Kindly let me know. Thank you

Share Improve this question edited Apr 3 at 1:05 tomcaptain asked Apr 1 at 2:10 tomcaptaintomcaptain 336 bronze badges 8
  • 1 Is there a reason you can't simply edit the form html by hand to make the desired change? – John Gordon Commented Apr 1 at 2:59
  • i mean when the form is posted to Django with the post request object! – tomcaptain Commented Apr 1 at 4:55
  • 1 What have you tried? This is a pretty basic Django situation. – Tim Roberts Commented Apr 1 at 4:58
  • i have tried to convert request.POST with the getlist function but couldn’t convert to Python list! Another practical scenario can be a series or array of input HTML checkboxes – tomcaptain Commented Apr 1 at 5:29
  • 1 We need more code to help you. Please post a minimal reproducible example that illustrates what you are trying to do. It should be complete enough that we can copy/paste it and run it ourselves. You can assume that we can create a new django project ourselves. Just provide any custom code that is needed to cause the behavior you are asking about. Note that it should be minimal. That means it doesn't need to be your entire project. Just post enough to show what you have done so far. That will probably include one or more views and a template. – Code-Apprentice Commented Apr 1 at 6:18
 |  Show 3 more comments

1 Answer 1

Reset to default 1

to handle both cases you can do-

allowed_extensions = request.POST.get("allowed-extensions", "").split(",")

本文标签: In Django how to convert HTML post input field values or csv values to Python listStack Overflow