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. scientist
    220812
  2. 윤재승
    yes
  3. labis98
    2022.02.23 좋은 강의 한번 더 들어요~~~!
  4. pmxsg
    2022.02.04
  5. labis98
    20220109 좋은 강의 감사합니다.
  6. 2021.09.10 완료
  7. 이택진
    210520
  8. 초딩 개발자
    2021/05/09
  9. jeisyoon
    2021.04.08 조건에 반응하는 웹 만들기 - OK
  10. VIBOT
    Ok
  11. 박민지
    2021.01.13
  12. hksap
    210101
  13. mBtion
    2020.10.14
  14. dagel0102
    20.10.09
  15. cgoing
    cgoing / 2020.10.02
  16. jiyeong
    2020.09.01.
  17. 권만진
    아마 form = cgi.FieldStorage()

    가 if 문 위에 있지 않아서 그런 것 아닐까요. form 이라는 변수가 정의되지 않았다고 하니까요
    대화보기
    • OneJae EE
      20.05.05 화 / 37세 비전공자 / 완료
    • line 5, in <module>
      if 'id' in form:
      NameError: name 'form' is not defined
      이렇게 나오는데 어떻게 해야되나요ㅠㅠㅠ
    • 악어
      2020-03-11 완료
    • 스티븐잡숴
      완료
    • apldeap
      12/26
    • xuanxi
      20191126
    • 쑤우
      수강완료.감사합니다~
    • 굼벵이
      완료
    • Ted
      20191004 Ted 완료!
    • 왕만두
      웹을 잘 몰라서 HTML과 CSS에서 엄청 헤맸는데 ㅠㅠ 다행히 리눅스랑 파이썬 코딩은 조금 해봐서 오히려 파이썬 들어오니까 내용이 쉽고 재밌네요! 감사합니다
    • Seankim
      if 'id' in form:
      pageId = form["id"].value
      else:
      pageId='Welcome'
    • 김귀인
      맞아요 빠져있는 것 같아요
      대화보기
      • sudo
        유튜브 재생목록에 해당강의가 누락되어있습니다 확인부탁드립니다
      • 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 자세히 보기