0
cherrypy로 제공되는 정적 컨텐츠를 사용자 정의하는 방법을 파악하려고합니다.CherryPy로 사용자 정의 정적 컨텐츠 제공
목표는 경로가/pub로 시작될 때 파일을 제공하는 것이지만 일반적으로 경로가 시작될 때 먼저 액세스를 확인하는 사용자 지정 함수를 추가하려고합니다.
설명서에 충분한 정보가 나와 있습니다. 여기에 내가 지금까지 가지고있는 것이 있습니다 ...
import cherrypy
from cherrypy.lib.static import serve_file
class Root(object):
# Somehow turn this into a handler for all files
def page(self):
if authorized(): # Check whether authenticated user may access the requested path
file_location = .... # Work out file location from request
print("Serving file from %s" % file_location)
return serve_file(file_location)
else:
return "Not Authorized"
if __name__ == '__main__':
serve_conf = {'/': {'tools.gzip.on': True},
'/pub': {
'tools.staticdir.on': True,
'tools.staticdir.dir': "/data/public",
'tools.staticdir.debug': True,
'log.screen': True
},
'/secure': { "PROBABLY CONFIGURE THE HANDLER HERE" }
}
cherrypy.quickstart(Root(), config=serve_conf)
[인증 도구 예] (https://github.com/GDG-Ukraine/gdg.org.ua/blob/master/src/GDGUkraine/lib/tools/authorize.py)를 참조하십시오. 'cherrypy.Tool' 클래스를 사용하고 [간단한 할당을 통해 등록됩니다] (https://github.com/GDG-Ukraine/gdg.org.ua/blob/master/src/GDGUkraine/lib/tools/__init__. py # L7). 이 코드가 클래스에 코드를 래핑하는 데 도움이되기를 바랍니다. – webKnjaZ