cgi and webserver
2481 ワード
前の文章を続けて、cgiとwebserverの設計について理解します:私たちがホームページの中でいくつかのデータを提出したい時、これらのデータはサーバーでどのように処理しますか:今testフォルダの下でhtmlを作成して、index.html入力ボックスとコミットボタンを書きます.
それからcgi-binフォルダの下にindexを書きます.py :
もしあなたが中国語を提出して、それから実行して表示できないならば、これは符号化の問題indexです.htmlでは主にaction指定パスとname指定フィールドindexである.pyでは主にcgiにフィールドを格納する方法が用いられる.
<html>
<head>
<meta charset="{CHARSET}">
<title> title>
head>
<body>
<form action="cgi-bin/index.py">
<input type="text" name="user"><input type="submit" value="submit">
form>
body>
html>
それからcgi-binフォルダの下にindexを書きます.py :
import cgi
form = cgi.FieldStorage()
print('Content-type: text/html
')
name = form['user'].value if 'user' in form else ' '
print('hello {0}'
.format(name))
もしあなたが中国語を提出して、それから実行して表示できないならば、これは符号化の問題indexです.htmlでは主にaction指定パスとname指定フィールドindexである.pyでは主にcgiにフィールドを格納する方法が用いられる.