정확하게 두 가지 요청을 허용하는 최소한의 웹 사이트를 만들려고합니다. 먼저 '/'에 대한 GET 요청으로 간단한 문자열로 응답해야합니다. 두 번째는 '/ put_url'에 대한 데이터 요청을 허용하는 PUT 요청입니다. 다음은 지금까지 내가 가지고있는 것입니다 :PUT 방법을 사용하는 미니멀리스트 체리 피 웹 사이트
import cherrypy
class Main(object):
@cherrypy.expose
def index(self):
return "Hy?"
class Uploader(object):
exposed = True
def PUT(self, data):
print "hello"
print data
if __name__ == '__main__':
conf = {
'/put_url': {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.response_headers.on': True,
'tools.response_headers.headers': [('Content-Type', 'text/plain')]
}
}
webapp = Main()
webapp.put_url = Uploader()
cherrypy.quickstart(webapp, '/', conf)
어떻게 작동합니까? 웬일인지 나는 이것을 이해할 수 없다. 감사.
문서 [이 예제] (http://docs.cherrypy.org/en/latest/tutorials.html#tutorial-7-give-us-a-rest)를 참조하십시오. –