def get_list(): sanitizer=html_sanitizer.Sanitizer() files=os.listdir("Data") liststr="" for item in files : item=sanitizer.sanitize(item) liststr=liststr+"<li><a href='Python.py?id={name}'>{name}</a></li>".format(name=item) return liststr
def getList(): sanitizer = html_sanitizer.Sanitizer() files = os.listdir('data') listStr = '' for item in files: item = sanitizer.sanitize(item) listStr = listStr + '<li><a href="index.py?id={name}">{name}</a></li>'. format(name=item) return listStr
def getList(): sanitizer = html_sanitizer.Sanitizer() files = os.listdir('data') # data 폴더 안의 파일 이름들을 가져와서 files에 list로 저장 liststr = '' for item in files: item = sanitizer.sanitize(itme) liststr = liststr + '<li><a href="index.py?id={name}">{name}</a></li>'.format( name=item) return liststr
def getList(): sanitizer = html_sanitizer.Sanitizer() files = os.listdir('data') # 맥OS 특성 상 맨 앞 히든파일 하나 pop으로 제거 (.dataStore 어쩌구 안 생기면 필요없을 수도 있음) # files.pop(0) listStr = '' for item in files: item = sanitizer.sanitize(item) listStr = listStr + '<li><a href="index.py?id={name}">{name}</a></li>'.format(name=item) return listStr
def get_list(): """Get names of the trekking courses data in the Data folder with sanitizing script code """ sanitizer = html_sanitizer.Sanitizer() files = os.listdir('data') liststr = '' for item in files: item = sanitizer.sanitize(item) liststr = liststr + '<li><i style="color:grey;"><a href="index.py?id={name}">{name}</a></i></li>'.format( name=item) return liststr
def getList(): sanitizer = html_sanitizer.Sanitizer() files = os.listdir('data') #data 디렉토리의 파일목록을 리스트로 변수에 담는다 listStr = '' #html 코드로 들어갈 string #{}로 포맷필드 이름을 입력하고, format() 안에 해당 변수 이름을 준다 for item in files: item = sanitizer.sanitize(item) listStr = listStr + '<li><a href="index.py?id={name}">{name}</a></li>'.format( name=item) #files의 목록을 하나씩 li 태그로 listStr에 추가해줌>밑의 html에 쓰임 return listStr
#!/usr/local/bin/python3 print("Content-Type: text/html") print() import cgi, os, view, html_sanitizer sanitizer = html_sanitizer.Sanitizer() form = cgi.FieldStorage() if 'id' in form: title = pageId = form["id"].value description = open('data/' + pageId, 'r').read() title = sanitizer.sanitize(title) description = sanitizer.sanitize(description) update_link = '<a href="update.py?id={}">update</a>'.format(pageId) delete_action = ''' <form action="process_delete.py" method="post"> <input type="hidden" name="pageId" value="{}"> <input type="submit" value="delete"> </form> '''.format(pageId) else: title = pageId = 'Welcome' description = 'Hello, web' update_link = '' delete_action = '' print('''<!doctype html> <html> <head> <title>WEB1 - Welcome</title> <meta charset="utf-8"> </head> <body>
#################################################################### #################################################################### ###################### html 한글깨짐해결코드 ######################## import sys import io sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding='utf-8') sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding='utf-8') #################################################################### #################################################################### #################################################################### import cgi import module import html_sanitizer sanitizer = html_sanitizer.Sanitizer() # default configuration form = cgi.FieldStorage() if 'id' in form: pageId = form['id'].value description = open('data/' + pageId, 'r').read() # need to Sanitizer description = description.replace('<', '<') description = description.replace('>', '>') description = sanitizer.sanitize(description) update_link = '<a href="update.py?id={}">update</a>'.format(pageId) delete_btn = ''' <form action='process_delete.py' method='post'>
#!/Library/Frameworks/Python.framework/Versions/3.8/bin/python3 print("Content-Type: text/html") # HTML is following print() # blank line, end of headers import cgi # cgi package를 사용하겠다 import os, view, html_sanitizer sanitizer = html_sanitizer.Sanitizer() # 보안 이슈를 해결하기 위한 html_saniziter package form = cgi.FieldStorage() if 'id' in form: title = pageId = form["id"].value description = open('data/' + pageId, 'r').read() # description = description.replace('<', '<') # 보안의 일종, javascript 코드를 입력하면, 화면에 그대로 표시되도록 함 # description = description.replace('>', '>') title = sanitizer.sanitize(title) description = sanitizer.sanitize(description) update_link = '<a href="update.py?id={}">update</a>'.format( pageId) # id 값이 있을 때만 update link 활성화 delete_action = ''' <form action="process_delete.py" method="post"> <input type="hidden" name="pageId" value="{}"> <input type="submit" value="delete"> </form> '''.format(pageId) else: title = pageId = 'welcome' description = 'Hello. Web'