Receive a form from very simple HTML and change the exported content depending on the content of the form. That guy. It's useful to remember when running with CGI.
index.html
<form method="POST" action="cgi-bin/index.py">
<p><input type="radio" value="part_a" name="choise_pattern">Pattern A</p>
<p><input type="radio" value="part_b" name="choise_pattern">Pattern B</p>
<p><input type="radio" value="part_c" name="choise_pattern">Pattern C</p>
</form>
Suppose you have HTML like the one above. Let's take the form in Python and divide the behavior according to the value of value. I will try to be very orthodox without doing any technical things.
index.py
import cgi
form = cgi.FieldStorage()
choose_pattern = form["choise_pattern"].value
print "Content-Type: text/html\n"
print """
<!DOCTYPE html>
<html lang="ja">
<head></head>
<body>
"""
if choose_pattern == "part_a":
print "<p>", u"Pattern A selected", "</p>
elif choose_pattern == "part_b":
print "<p>", u"Pattern B selected", "</p>
elif choose_pattern == "part_c":
print "<p>", u"Pattern C selected", "</p>
print """
</body>
</html>
"""
Originally, there is a process when nothing is selected, but I think that it should be dealt with by applying a validator check before sending.
By applying this, you can also create a site builder that exports HTML and combines it according to the selected design.
That's why I made it. I just made it. A Python script receives the selected design block in a form and spits out HTML. A tool that can be viewed immediately with PREVIEW.
I tried to design it like that using Bootstrap, but I have no idea where the demand is.
http://app.jiriki.co.jp/lp-creater/
Recommended Posts