0

I have designed a basic REST API with flask and Python 3 to restart services on a locked down application. Using Postman, I would send a HTTP POST with anapplication/json body similar to;

{
    "fqdn" : ["my-fqdn-1.domain.com", "my-fqdn-2.domain.com"],
    "control_type" : "Start",
    "service" : ["Service 1", "Service 2"]
}

Sometimes, fqdn may be just 1 entry, other times, it could be 10. The same goes for service, sometime I might want to stop 1 service, other times stop 5. So far everything is working fine but now I would like to create a HTML form to provide similar functionality. On the form, I was thinking of having 1 row for fqdn, 1 row for service and then a dropdown for control_type. I could then dynamically add more rows for fqdn and service using Javascript similar to this Stackoverflow question.

What I am trying to figure out is how I would convert for example HTML inputs (not real HTML, just example)<name=Service1>Service1</> <name=Service2>Service2</> <name=Service3>Service4</> back to a Python List. For single values, it is easy;

fqdn = request.form["fqdn"]
service = request.form["service"]

but if I don't know how many rows to expect, I can't figure out how to process it.

3
  • Have you considered using a list and checkboxes? Commented Jul 20, 2018 at 1:15
  • The problem with using a list is that the only thing that is static is control_type. fqdn and service could be different for different users hence I was thinking the only way would be input. Commented Jul 20, 2018 at 1:21
  • if you are using wtforms that come with Flask, you should be able to make a macro that does this Commented Jul 21, 2018 at 0:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.