본문 바로가기

WEB/Python10

[Python] 삭제하기(form, remove) [생활코딩] 활용 - 삭제 구현 삭제버튼 만들기 index.py #!/usr/local/bin/python3 print("content-type:text/html; charset=UTF-8\n") import cgi,os files = os.listdir('data') liststr = '' for item in files: liststr = liststr + '{name}'.format(name=item) form = cgi.FieldStorage() if 'id' in form: pageId = form["id"].value description = open('data/'+pageId).read() update_link = 'update'.format(pageId=pageId) delete_actio.. 2020. 8. 23.
[Python] 업데이트하기(input, format, rename) [생활코딩] 활용 - 수정 구현 pageId값 유무에 따라 update 버튼 출력 index.py #!/usr/local/bin/python3 print("content-type:text/html; charset=UTF-8\n") import cgi,os files = os.listdir('data') liststr = '' for item in files: liststr = liststr + '{name}'.format(name=item) form = cgi.FieldStorage() if 'id' in form: pageId = form["id"].value description = open('data/'+pageId).read() update_link = 'update'.format(pageid=p.. 2020. 8. 23.
[Python] form 값 처리하기(FieldStorage, open, Location) [생활코딩] 활용 - 생성 구현 1 - form [생활코딩] 활용 - 생성 구현 2 - 전송한 정보의 처리 from 만들기 create.py #!/usr/local/bin/python3 print("content-type:text/html; charset=UTF-8\n") import cgi,os files = os.listdir('data') liststr = '' for item in files: liststr = liststr + '{name}'.format(name=item) form = cgi.FieldStorage() if 'id' in form: pageId = form["id"].value description = open('data/'+pageId).read() else: pageId =.. 2020. 8. 23.
[Python] 파일목록 읽기 - listdir, 반복문 - for [생활코딩] 활용 - 반복문을 이용해서 글목록 구현 파일 목록 읽기 listdir() import os # os모듈 가져오기 files = os.listdir('data') # 메소드 listdir는 디렉토리안 파일명을 반환함 반복문으로 리스트 만들기 for (value) in (values) : liststr = '' for item in files: liststr = liststr + '{name}'.format(name=item) 2020. 8. 23.
[Python] 파일 읽기 open().read() [생활코딩] 활용 - 파일 기능을 이용해 본문 구현 open()는 파일명과 파일 처리방식을 입력 받아 결과를 준다. open(파일명, 읽기모드) = open('file', 'r') --- r은 기본값이라 생략가능 open(파일명, 쓰기모드) = open('file', 'w') open(파일명, 추가모드) = open('file', 'a') open().read()는 파일의 내용을 문자열로 반환한다. [실습] 1. data폴더에 HTML, CSS, Javascript 파일 생성 2. index.py 에서 data 폴더의 파일 읽어 description에 담기 #!/usr/local/bin/python3 print("content-type:text/html; charset=UTF-8\n") import cg.. 2020. 8. 22.
[Python] cgi.FieldStorage() [생활코딩] 활용 - 조건에 반응하는 앱 만들기 CGI은 웹 서버에 의해 호출되며, 사용자에 의해 제출된 입력 정보를 처리한다. 그 정보는 호스트 이름, URL, 쿼리문자열 등이 될 수 있다. FieldStorage을 cgi의 클래스로 제출된 양식의 데이터를 얻을 수 있다. index.py print(cgi.FieldStorage()) http://localhost:8000/index.py?id=HTML로 접속하면 출력값은 FieldStorage(None, None, [MiniFieldStorage('id', 'HTML')]) 쿼리스트링이 MiniFieldStorage에 저장된 것이다. print(cgi.FieldStorage()["id"]) [결과] MiniFieldStorage('id', 'HTML'.. 2020. 8. 22.
반응형