수업소개
URL의 query string을 입력 값으로 웹애플리케이션으로 끌어오는 방법을 소개합니다.
강의
이 수업의 예제에서는 접속 URL에 ?id가 포함되어 있어야 오류없이 동작합니다.
소스코드
index.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #!/usr/local/bin/python3 print ( "Content-Type: text/html" ) print () import cgi form = cgi.FieldStorage() pageId = form[ "id" ].value print ( '''<!doctype html> <html> <head> <title>WEB1 - Welcome</title> <meta charset="utf-8"> </head> <body> <h1><a href="index.py">WEB</a></h1> <ol> <li><a href="index.py?id=HTML">HTML</a></li> <li><a href="index.py?id=CSS">CSS</a></li> <li><a href="index.py?id=JavaScript">JavaScript</a></li> </ol> <h2>{title}</h2> <p>The World Wide Web (abbreviated WWW or the Web) is an information space where documents and other web resources are identified by Uniform Resource Locators (URLs), interlinked by hypertext links, and can be accessed via the Internet.[1] English scientist Tim Berners-Lee invented the World Wide Web in 1989. He wrote the first web browser computer program in 1990 while employed at CERN in Switzerland.[2][3] The Web browser was released outside of CERN in 1991, first to other research institutions starting in January 1991 and to the general public on the Internet in August 1991. </p> </body> </html> ''' . format (title = pageId)) |