python -m CGIHTTPServer &
the end.
☆ It is assumed that you have the following knowledge. There is an execution example at the bottom.
--The directory where this command is ** turned! ** becomes the server root. --When you stop it, find the process that has gone behind and kill it (ps ax | grep python), or cause an error and rampage. --If you have xxx.html, it will be http://127.0.0.1:8000/xxx.html --CGI script is placed in ** cgi-bin / ○○ .py ** (If you don't like the folder, start the server normally) --Grant execute permission if it is a script
chmod 0755 cgi-bin/○○.py
--If it is a script, you need to specify the path of the program to execute
#!/usr/bin/python
# -*- coding: utf-8 -*-
--If you want the browser to recognize it as a page, issue the Content-type yourself (since you can send your favorite headers)
print "Content-type: text/html\n\n"
--If you run it as a script, you will use the cgi module.
#Get the value honyarara from the form, query
import cgi
form = cgi.FieldStorage()
honyarara = form["honyarara"].value
--When you want to see if the script works
vi cgi-bin/test.py chmod 0755 cgi-bin/test.py python -m CGIHTTPServer & curl http://127.0.0.1:8000/cgi-bin/test.py?q=hello
Ah, hello
test.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import cgi
form = cgi.FieldStorage()
print "Content-type: text/html\n\n"
print form["q"].value
Recommended Posts