PythonCGI
python CGI CGI๋ Common Gateway Interface์ ์ฝ์๋ค. web application์ ๋ง๋ค ์ ์๋ ์ธ์ด๋ ruby, java, php ๋ฑ ๋ค์ํ์ง๋ง ๋ชจ๋ CGI ๊ท์ฝ์ ๋ฐ๋ผ web server์ ํต์ ํ๋ค. web server๋ ์ฌ์ฉ์์ ์์ฒญ์ ๋ฐ์ผ๋ฉด ์ฝ์๋ ์ด๋ฆ์ ๋ฐ์ดํฐ๋ฅผ ํ๊ฒฝ๋ณ์๋ก web application์ ์ ๋ฌํ์ฌ ์๋ก ๊ต๋ฅํ๋ค. apache์์ python์ ์ด์ฉํด web application์ ๋ง๋ค์ด web server์ ํต์ ํด ๋ณด์. $ a2enmod CGI ๋ช ๋ น์ผ๋ก apache์ CGI๋ฅผ ์ผ ์ฃผ๊ณ , sudo service apache2 restart ๋ก ์ค์ ์ ์ฉ /var/log/apache2/error.log ์์ apache ์คํ์ ๋ฐ์ํ ์๋ฌ ๋ก๊ทธ๊ฐ ๋ด๊ฒจ์๋ค. ์น ๋ธ๋ผ์ฐ์ ๊ฐ ์น ์๋ฒ์ ์์ฒญํ ๋ ์น ์๋ฒ๋ ์๋ต์ผ๋ก ์น ํ์ด์ง์ ๋ฐ์ดํฐ ํ์ (ํค๋)์ ํจ๊ป ์น ํ์ด์ง๋ฅผ ์ ์กํ๋ค. python CGI๋ก๋ print("content-type:text/html; charset=UTF-8\n") ์ ๊ฐ์ด ํค๋๋ฅผ ํ๊ธฐ๋ธ๋ค. ํค๋๋ฅผ ์ถ๋ ฅํ ๋ค์ ๋ถํฐ๋ body ๋ถ๋ถ์ด ์ถ๋ ฅ๋๋ค. ํน์ ์ฃผ์๋ก Redirection์ ํ ๋์๋ print("location : index.py?id=title")์ ์ด์ฉํ๋ค. ( โ:โ ์ดํ ๋ถํฐ โ"โ ๊น์ง๋ ์ํ๋๋๋ก ์์ฑ) formatting string์์ ํน์ ๋ฌธ์์ด์ ๋ค๋ฅธ ๋ฌธ์๋ก ์นํํ๋ ๊ธฐ๋ฅ ex) '{} {}'.format('one','tow') ex) '{a} {b}'.format(a='hello', b='world') python ํ์ผ์์ ๋ฌธ์์ด๊ณผ format ํจ์๋ฅผ ์ด์ฉํ์ฌ ๋์ html์ ๊ตฌํ ๊ฐ๋ฅํ๋ค. CGI ๋ชจ๋ import cgi ๋ก ๋ชจ๋์ ๋ก๋ํด ์ฌ์ฉํ๋ค. form = cgi.FieldStorage() form์ jQuery์ ๊ฐ์ ์ญํ ์ ํ๋ค. ex) pageId = form['id'].value : page์ id๋ฅผ ๊ฐ์ ธ์จ๋ค. HTML ์ฐ๋ input ํ๊ทธ์ name ์์ฑ : input ํ๊ทธ๋ฅผ ํน์ ์ด๋ฆ์ผ๋ก CGI์ ์ ๋ฌํจ ex) ...