WEB2 - Python

활용 - 조건에 반응하는 앱 만들기

수업소개

조건문을 활용해서 URL query string에 id 값이 있는지 여부에 따라서 다르게 동작하는 웹앱을 구현해봅시다.

 

 

강의

 

 

소스코드

변경사항

#!/usr/local/bin/python3
print("Content-Type: text/html")
print()
import cgi
form = cgi.FieldStorage()
if 'id' in form:
    pageId = form["id"].value
else:
    pageId = 'Welcome'
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))

 

댓글

댓글 본문
작성자
비밀번호
  1. 김귀인
    맞아요 빠져있는 것 같아요
    대화보기
    • 유튜브 재생목록에 해당강의가 누락되어있습니다 확인부탁드립니다
    • Yesugei
      index.py 의 5번째 줄에
      form = cgi.FieldStorage()
      이걸 안넣어서 그런거 아닐까요?
      대화보기
      • 박태형
        [Wed May 02 15:35:30.630037 2018] [cgi:error] [pid 7828:tid 1136] [client 127.0.0.1:54041] AH01215: Traceback (most recent call last):\r: C:/Bitnami/wampstack-7.1.16-0/apache2/htdocs/index.py
        [Wed May 02 15:35:30.635049 2018] [cgi:error] [pid 7828:tid 1136] [client 127.0.0.1:54041] AH01215: File "C:/Bitnami/wampstack-7.1.16-0/apache2/htdocs/index.py", line 5, in <module>\r: C:/Bitnami/wampstack-7.1.16-0/apache2/htdocs/index.py
        [Wed May 02 15:35:30.635049 2018] [cgi:error] [pid 7828:tid 1136] [client 127.0.0.1:54041] AH01215: form = cgi.FieldStorasge()\r: C:/Bitnami/wampstack-7.1.16-0/apache2/htdocs/index.py
        [Wed May 02 15:35:30.635049 2018] [cgi:error] [pid 7828:tid 1136] [client 127.0.0.1:54041] AH01215: AttributeError: module 'cgi' has no attribute 'FieldStorasge'\r: C:/Bitnami/wampstack-7.1.16-0/apache2/htdocs/index.py
        라고 나오는데 뭐가 문제일까요
      • PassionOfStudy
        2018-03-28 - 3일차_네 번째 수강완료!

        조건문을 이용하여 주어진 문제를 해결하는 방법에 대해 알게되었고,
        form안에 id값의 존재여부를 in을 통하여 접근할 수 있다는 것을 알게되었습니다.
      graphittie 자세히 보기