i need static files(html, scryptes, pictures, css) in tornado. standart file handler not useful, becuse request url must not contain static prefix. server used in mobile application project.
the code:
application = tornado.web.application([     (r"/(.*)", static), ])   class static(tornado.web.requesthandler): def get(self, url):     print 'static', url     try:         data = open(r'static/'+url,'rb').read()         print 'file found', url     except:         data = 'error. file not found'         print 'file not found', url     self.write(data) atempt picture failed. browser shows different characters. html pages shown, seems css load faled.
is thre way it?
python 2.7, windows 7 x64 (just test).
problem solved:
    (r"/(.*)", tornado.web.staticfilehandler, {"path": r"c:\python27\***\static"}), 
you use tornado's ability server static file:
application = tornado.web.application(     [(r"/(.*)", static)],     static_path="your path here" ) but implies calling url:  www.domain.com/static/anyfile.txt
edit: if want have different base url, add param: static_url_prefix="/toto/" when creating application
then: www.domain.com/toto/anyfile.txt serve file
Comments
Post a Comment