CGI server (1) python edition in one line

Yes, * turn! *

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

CGI server (1) python edition in one line
Fizzbuzz in Python (in one line)
Make python segfault in one line
One liner webServer (with CGI) in python
Decompose command arguments in one line in Python
[Python] Invert bool value in one line
One liner in Python
DNS server in Python ....
Make a rock-paper-scissors game in one line (python)
DMD in Python one dimension
Try LINE Notify in Python
Run CGI written in python on Sakura's rental server
Decrypt one line of code in Python lambda, map, list
Write an HTTP / 2 server in Python
Prime number enumeration in one line
I tried Line notification in Python
[Introduction] Insert line breaks in Python 3
Implemented in 1 minute! LINE Notify in Python
[Python] [3D line graph] Multiple data in one graph, axis values in characters
Handle multiple python versions in one jupyter
Displaying candlestick charts in Python (matplotlib edition)
Line graphs and scale lines in python
Build CGI Server running on Python 3 on Docker
Read the file line by line in Python
Read the file line by line in Python
Get Started with TopCoder in Python (2020 Edition)
Displaying candlestick charts in Python (Plotly edition)
[Python] Read the specified line in the file
Template for creating command line applications in Python
Quadtree in Python --2
Python in optimization
CURL in python
One liner that outputs multiplication tables in Python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Try implementing two stacks in one array in Python
Unittest in python
One liner to 100% CPU1 core usage in Python
Epoch in Python
Discord in Python
Python hand play (one line notation of if)
Python CGI basics
Sudoku in Python
DCI in Python
quicksort in python
Set up a test SMTP server in Python.
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
LINE heroku python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
Multiple graphs are displayed in one window (python)
Get files, functions, line numbers running in python