[Fixed]-Django Dynamic name attribute and getting values in views.py

1👍

The object request.POST behaves like a dictionary, so you can easily iterate over the keys and keep the ones you want.

For example:

input_names = [name for name in request.POST.keys() if name.startswith('software-name-')]
for input_name in input_names:
    soft_name = request.POST[input_name]

You could even get directly the tuples (name, value) like so:

inputs = [(n, v) for n, v in request.POST.iteritems() if n.startswith('software-name-')]

Leave a comment