Receive the form in Python and do various things

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

Receive the form in Python and do various things
Receive and display HTML form data in Python
Check and receive Serial port in Python (Port check)
About the difference between "==" and "is" in python
Output in the form of a python array
POST JSON in Python and receive it in PHP
Submit in [Python] form
Let's play with Python Receive and save / display the text of the input form
The simplest Python memo in Japan (classes and objects)
[AWS IoT] Register things in AWS IoT using the AWS IoT Python SDK
Carefully understand the exponential distribution and draw in Python
Plot and understand the multivariate normal distribution in Python
Send and receive Gmail via the Gmail API using Python
Carefully understand the Poisson distribution and draw in Python
(◎◎) {Let's let Python do the boring things) ......... (Hey? Let's let Python do the homework} (゜) (゜)
% And str.format () in Python. Which one do you use?
Find the Hermitian matrix and its eigenvalues in Python
To do the equivalent of Ruby's ObjectSpace._id2ref in Python
Download the file in Python
Find the difference in Python
Receive runtime arguments in Python 2.7
Stack and Queue in Python
Unittest and CI in Python
Get the MIME type in Python and determine the file format
Sort and output the elements in the list as elements and multiples in Python.
Various ways to calculate the similarity between data in python
[2020 version] Let Python do all the tax and take-home calculations
Manipulate the clipboard in Python and paste the table into Excel
I tried programming the chi-square test in Python and Java.
[Python] Display the elapsed time in hours, minutes, and seconds (00:00:00)
Get the current date and time in Python, considering the time difference
"Let Python do the boring things" exercise ~ Command line mailer ~
The websocket of toio (nodejs) and python / websocket do not connect.
[Tips] Problems and solutions in the development of python + kivy
Just try to receive a webhook in ngrok and python
I implemented N-Queen in various languages and measured the speed
Graph the Poisson distribution and the Poisson cumulative distribution in Python and Java, respectively.
How to do "Lending and borrowing JS methods (the one who uses apply)" in Python
Determine the date and time format in Python and convert to Unixtime
[Python] How to do PCA in Python
The story of Python and the story of NaN
MIDI packages in Python midi and pretty_midi
Count the number of Thai and Arabic characters well in Python
Difference between == and is in python
View photos in Python and html
Sorting algorithm and implementation in Python
Python in the browser: Brython's recommendation
Save the binary file in Python
Hit the Sesami API in Python
[Python] df Read and do the first memo (NaN confirmation etc.)
New Python grammar and features not mentioned in the introductory book
Get the desktop path in Python
Manipulate files and folders in Python
About dtypes in Python and Cython
Get the script path in Python
In the python command python points to python3.8
Implement the Singleton pattern in Python
Assignments and changes in Python objects
Check and move directories in Python
Ciphertext in Python: IND-CCA2 and RSA-OAEP
Hashing data in R and Python