(Oct-20-2016, 12:07 AM)adi.6194 Wrote: I want to create an HTML select dropdown where the options are taken from a python list. Is this possible??
import cgitb cgitb.enable() import cgi form = cgi.FieldStorage() lister = ['a','b','c'] html_list = '' for value in lister: html_list += '<option value={0}>{0}</option>'.format(value) html = """Content-type: text/html\n <html> <head> </head> <body> <select> {OPTIONS} </select> </body> </html> """.format( OPTIONS=html_list, ) print(html)and of course instead of +=, you can append the option string to a list, and then join them at the end.
Recommended Tutorials: